<p>Anything you can do from the command line you can also do from the JSON API which means that the same unlock command could be sent from within code just as easily. To my knowledge there is no pre-built utility capable of this, but the API is simple enough that I can't imagine it being terribly difficult to actually build such a tool.</p>

<hr>

<p><strong>Edit:</strong> <em>It was much easier than expected to do this in Python. Assuming you have Python's <a href="http://json-rpc.org/wiki/python-json-rpc" rel="nofollow">JSON-RPC</a> module installed just use this code:</em></p>

<pre><code>from jsonrpc import ServiceProxy
from getpass import getpass
access = ServiceProxy("http://127.0.0.1:8332")
pwd = getpass("Enter wallet passphrase: ")
access.walletpassphrase(pwd, 60)
</code></pre>

<p>Similarly you could call <code>access.walletlock()</code> to lock the wallet on demand and <code>walletpassphrasechange(old, new)</code> to change the passphrase without ever having it see the command line.</p>

<hr>

<p><strong>Edit 2:</strong> <em>I also submitted an <a href="https://github.com/bitcoin/bitcoin/issues/548" rel="nofollow">issue</a> to the devs on github on your behalf.</em></p>

<p><strong>Edit 3:</strong> <em>A pull request containing my python scripts has been accepted. Downloading the bitcoin source <a href="https://github.com/bitcoin/bitcoin" rel="nofollow">from github</a> now includes scripts for this purpose in contrib/wallettools</em></p>

<p><strong>Edit 4:</strong> <em>A <a href="https://github.com/bitcoin/bitcoin/issues/2318" rel="nofollow">new bug report</a> was filed to request that the builtin command behaves properly.</em></p>

CC BY-SA 3.0
2011-10-03T14:40:53.840Z
2013-02-19T18:10:01.483Z
2013-02-19T18:10:01.483Z
David Perry
<p>You can avoid having the password show up in the shell history like this:</p>

<pre><code>$ read x
password goes here
$ bitcoind walletpassphrase "$x" 60
$ x=
$ 
</code></pre>

<p>The <code>read x</code> command reads the next line of text you type and puts it into a shell variable <code>x</code>.</p>

<p>The <code>x=</code> command overwrites the shell variable; otherwise $x will hold your password until you exit the current shell.</p>

<p>It shows up in the history like this:</p>

<pre><code>2032  read x
2033  bitcoind walletpassphrase "$x" 60
2034  x=
2035  history
</code></pre>

<p>I expect the password will show up in /proc/ while the <code>bitcoind</code> command is running, but that should be only for a fraction of a second.</p>

CC BY-SA 3.0
2014-05-02T21:22:37.830Z
While this hides the passphrase from the shell history it will still show up in other places (`ps -ax` or `ps -ef`, for example, will show the `bitcoind` command as invoked, including the *value* of `$x`)
voretaq7
CC BY-SA 3.0
2014-05-03T07:35:58.227Z
@voretaq7 no it doesnt show up in `ps`, see [this](http://serverfault.com/q/592744/116529) updated question.
q9f
CC BY-SA 3.0
2014-05-04T05:47:04.447Z
It shows up in ps output for me, but only for as long as the bitcoind command takes to run, which is approximately no time at all.  Try "sleep $x" where x is 999, then 'ps -ef | grep sleep' in another window to see it.
Chris Moore
CC BY-SA 3.0
2012-02-05T18:48:28.463Z
2012-02-05T18:48:28.463Z
Chris Moore
<p>The official developer answer is to use the provided python wrapper in <code>contrib/bitrpc/bitrpc.py</code> (<a href="https://github.com/bitcoin/bitcoin/blob/master/contrib/bitrpc/bitrpc.py" rel="nofollow">github</a>):</p>

<blockquote>
  <p>It asks for a password in a secure way if you use the command <code>walletpassphrase</code>, for example. There are no plans to add interactive functionality to <code>bitcoin-cli</code>. </p>
</blockquote>

<p>and:</p>

<blockquote>
  <p><code>bitcoin-cli</code> will remain as-is and not gain interactive functionality.</p>
</blockquote>

<p>Source: <a href="https://github.com/bitcoin/bitcoin/issues/2318" rel="nofollow">#2318</a></p>

<p>Unlock wallet: </p>

<pre><code>$ python bitrpc.py walletpassphrase
</code></pre>

<p>Change passphrase:</p>

<pre><code>$ python bitrpc.py walletpassphrasechange
</code></pre>

<p><a href="https://github.com/bitcoin/bitcoin/tree/master/contrib/bitrpc" rel="nofollow">https://github.com/bitcoin/bitcoin/tree/master/contrib/bitrpc</a></p>

CC BY-SA 3.0
2016-03-22T01:26:29.553Z
this file not longer exists.
erikvold
CC BY-SA 3.0
2014-12-31T16:52:43.063Z
2014-12-31T16:52:43.063Z
q9f
<p>While in command prompt press <kbd>ALT</kbd>+<kbd>F7</kbd> to delete all commands stored in memory for the current history buffer.</p>

CC BY-SA 3.0
2011-10-03T17:08:13.527Z
That solves the problem for now but it's really not acceptable for the passphrase to appear in the buffer in the first place. Also, is the buffer held solely in memory or is it at some point written to disk? If so, does Alt+F7 securely destroy the contents of such files or simply delete them?
David Perry
CC BY-SA 3.0
2011-10-03T21:23:35.667Z
The buffer is held solely in memory, and assuming user won't forget to clear history, I don't see how it's less secure then having additional prompt for password. Because if a malicious program have access to cmd memory buffer that also means it can intercept password input directly from keyboard.
Serith
CC BY-SA 3.0
2011-10-03T23:14:43.827Z
I don't think it's memory-grabbing malware we're concerned with here so much as multi-user PCs and forgetting to clear the buffer.
David Perry
CC BY-SA 3.0
2011-10-08T04:22:43.263Z
What operating system does this keyboard shortcut work in?
akaihola
CC BY-SA 3.0
2011-10-08T15:20:44.217Z
@akaihola, Windows Command Prompt
Serith
CC BY-SA 3.0
2011-10-03T14:51:47.940Z
2011-10-03T14:51:47.940Z
Serith
<p>You should now use <code>bitcoin-cli -stdinwalletpassphrase walletpassphrase 10</code> where 10 is the number of seconds you want to leave your wallet unlocked. <code>-stdinwalletpassphrase</code> was added in this PR: <a href="https://github.com/bitcoin/bitcoin/pull/13716" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/pull/13716</a></p>

CC BY-SA 4.0
2020-08-18T06:51:24.417Z
2020-08-18T06:51:24.417Z
Timothy Zorn
<p>If you prefix a command with space like ' echo hello world' it will not be stored in the history. This may be a bash only feature and idk if it can be disabled. Test it.
The risk here is that you may forget the space eventually.</p>

CC BY-SA 4.0
2022-10-01T16:50:35.707Z
the way to tell bash not to store history is to set $HISTFILE to /dev/null
Mercedes
CC BY-SA 4.0
2022-10-02T17:03:51.657Z
@Mercedes You mean not store history at all or just for one command? What's wrong with ' ' prefix?
darsie
CC BY-SA 4.0
2022-09-21T22:46:16.750Z
2022-09-22T10:21:47.453Z
2022-09-22T10:21:47.453Z
darsie
<p>With bitcoin 0.4.0 I have encrypted my wallet. Now when I would want to use bitcoind, the only way to send money is to provide my wallet decryption key on the cmd line first. I do not want to do that as my password will show up in the shell history. </p>

<p>Is there a way to let bitcoind ask for the wallet passphrase?</p>

CC BY-SA 3.0
2016-12-21T17:09:14.260Z
See this related post: http://security.stackexchange.com/questions/146019/input-password-to-bitcoin-cli
e18r
CC BY-SA 3.0
2017-02-28T20:16:15.130Z
And this: http://serverfault.com/q/592744/116529
q9f
<bitcoind>
Is there a way to provide the walletpassphrase to bitcoind without exposing it on the cmdline?
Peter Smit
# Is there a way to provide the walletpassphrase to bitcoind without exposing it on the cmdline?

(Asked by: username_0 on 2011-10-03)

With bitcoin 0.4.0 I have encrypted my wallet. Now when I would want to use bitcoind, the only way to send money is to provide my wallet decryption key on the cmd line first. I do not want to do that as my password will show up in the shell history.

Is there a way to let bitcoind ask for the wallet passphrase?

**Tags:** bitcoind

> **Comments:**
> **username_1**: See this related post: http://security.stackexchange.com/questions/146019/input-password-to-bitcoin-cli  
> **username_2**: And this: http://serverfault.com/q/592744/116529  

---

## 6 answers

### Answer by username_3 on 2011-10-03. Score: 13

Anything you can do from the command line you can also do from the JSON API which means that the same unlock command could be sent from within code just as easily. To my knowledge there is no pre-built utility capable of this, but the API is simple enough that I can't imagine it being terribly difficult to actually build such a tool.

---

**Edit:** *It was much easier than expected to do this in Python. Assuming you have Python's [JSON-RPC](http://json-rpc.org/wiki/python-json-rpc) module installed just use this code:*

```
from jsonrpc import ServiceProxy
from getpass import getpass
access = ServiceProxy("http://127.0.0.1:8332")
pwd = getpass("Enter wallet passphrase: ")
access.walletpassphrase(pwd, 60)

```

Similarly you could call `access.walletlock()` to lock the wallet on demand and `walletpassphrasechange(old, new)` to change the passphrase without ever having it see the command line.

---

**Edit 2:** *I also submitted an [issue](https://github.com/bitcoin/bitcoin/issues/548) to the devs on github on your behalf.*

**Edit 3:** *A pull request containing my python scripts has been accepted. Downloading the bitcoin source [from github](https://github.com/bitcoin/bitcoin) now includes scripts for this purpose in contrib/wallettools*

**Edit 4:** *A [new bug report](https://github.com/bitcoin/bitcoin/issues/2318) was filed to request that the builtin command behaves properly.*


---

### Answer by username_4 on 2012-02-05. Score: 10

You can avoid having the password show up in the shell history like this:

```
$ read x
password goes here
$ bitcoind walletpassphrase "$x" 60
$ x=
$ 

```

The `read x` command reads the next line of text you type and puts it into a shell variable `x`.

The `x=` command overwrites the shell variable; otherwise $x will hold your password until you exit the current shell.

It shows up in the history like this:

```
2032  read x
2033  bitcoind walletpassphrase "$x" 60
2034  x=
2035  history

```

I expect the password will show up in /proc/ while the `bitcoind` command is running, but that should be only for a fraction of a second.

> **Comments:**
> **username_5**: While this hides the passphrase from the shell history it will still show up in other places (`ps -ax` or `ps -ef`, for example, will show the `bitcoind` command as invoked, including the *value* of `$x`)  
> **username_2**: @username_5 no it doesnt show up in `ps`, see [this](http://serverfault.com/q/592744/116529) updated question.  
> **username_4**: It shows up in ps output for me, but only for as long as the bitcoind command takes to run, which is approximately no time at all.  Try "sleep $x" where x is 999, then 'ps -ef | grep sleep' in another window to see it.  

---

### Answer by username_2 on 2014-12-31. Score: 1

The official developer answer is to use the provided python wrapper in `contrib/bitrpc/bitrpc.py` ([github](https://github.com/bitcoin/bitcoin/blob/master/contrib/bitrpc/bitrpc.py)):

> It asks for a password in a secure way if you use the command `walletpassphrase`, for example. There are no plans to add interactive functionality to `bitcoin-cli`.

and:

> `bitcoin-cli` will remain as-is and not gain interactive functionality.

Source: [#2318](https://github.com/bitcoin/bitcoin/issues/2318)

Unlock wallet:

```
$ python bitrpc.py walletpassphrase

```

Change passphrase:

```
$ python bitrpc.py walletpassphrasechange

```

<https://github.com/bitcoin/bitcoin/tree/master/contrib/bitrpc>

> **Comments:**
> **username_6**: this file not longer exists.  

---

### Answer by username_7 on 2011-10-03. Score: 0

While in command prompt press `ALT`+`F7` to delete all commands stored in memory for the current history buffer.

> **Comments:**
> **username_3**: That solves the problem for now but it's really not acceptable for the passphrase to appear in the buffer in the first place. Also, is the buffer held solely in memory or is it at some point written to disk? If so, does Alt+F7 securely destroy the contents of such files or simply delete them?  
> **username_7**: The buffer is held solely in memory, and assuming user won't forget to clear history, I don't see how it's less secure then having additional prompt for password. Because if a malicious program have access to cmd memory buffer that also means it can intercept password input directly from keyboard.  
> **username_3**: I don't think it's memory-grabbing malware we're concerned with here so much as multi-user PCs and forgetting to clear the buffer.  
> **username_8**: What operating system does this keyboard shortcut work in?  
> **username_7**: @username_8, Windows Command Prompt  

---

### Answer by username_9 on 2020-08-18. Score: 0

You should now use `bitcoin-cli -stdinwalletpassphrase walletpassphrase 10` where 10 is the number of seconds you want to leave your wallet unlocked. `-stdinwalletpassphrase` was added in this PR: <https://github.com/bitcoin/bitcoin/pull/13716>


---

### Answer by username_10 on 2022-09-21. Score: -1

If you prefix a command with space like ' echo hello world' it will not be stored in the history. This may be a bash only feature and idk if it can be disabled. Test it.
The risk here is that you may forget the space eventually.

> **Comments:**
> **username_11**: the way to tell bash not to store history is to set $HISTFILE to /dev/null  
> **username_10**: @username_11 You mean not store history at all or just for one command? What's wrong with ' ' prefix?  

---

