<p><code>bitcoin-cli</code> has to be run with the same <code>user</code> as <code>bitcoind</code>. </p>

<p>Otherwise it will check for the configuration file in the wrong directory, because the <strong>default directory</strong> is the <code>home</code> directory of the user the process is run by.</p>

CC BY-SA 4.0
2019-08-29T07:07:49.187Z
2019-08-29T07:07:49.187Z
bomben
<p>The bitcoin-cli use the bitcoin-rpc, so for used a bitcoin-cli, you must ran the bitcoind with the configuration and when it is OK, you can get command with the bitcoin-cli</p>

<p>A simple file configuration could be it</p>

<pre><code>##
## bitcoin.conf configuration file. Lines beginning with # are comments.
##
# On client-side, you add the normal user/password pair to send commands:
rpcuser=alice
rpcpassword=bob
</code></pre>

<p>or you can run the <code>bitcoind with this command bitcoind -rpcuser=alice -rpcpassword=bob</code></p>

CC BY-SA 4.0
2019-08-28T19:18:16.517Z
2019-08-28T19:18:16.517Z
vincenzopalazzo
<p>I have a <code>/ect/systemd/system/bitcoin.service</code> with the following content and I am wondering, why <code>bitcoin-cli getinfo</code> tells me about a configuration file elsewhere:</p>

<pre><code>error: Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set.  See -rpcpassword and -stdinrpcpass.  Configuration file: (/home/pi/.bitcoin/bitcoin.conf)
</code></pre>

<p>Content of <code>bitcoin.service</code>, especially <code>-conf=/home/bitcoin/.bitcoin/bitcoin.conf</code>:</p>

<pre><code>[Unit]
Description=Bitcoin daemon
After=network.target
[Service]
ExecStart=/usr/local/bin/bitcoind -conf=/home/bitcoin/.bitcoin/bitcoin.conf -pid=/home/bitcoin/.bitcoin/bitcoind.pid
# Creates /run/bitcoind owned by bitcoin
RuntimeDirectory=bitcoind
User=bitcoin
Type=forking
PIDFile=/home/bitcoin/.bitcoin/bitcoind.pid
Restart=on-failure
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true
# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target
</code></pre>

CC BY-SA 4.0
2019-08-28T08:57:17.673Z
bacause it not have the information for the rpc framework, this is an comple example of bitcoin.con, [click me](https://github.com/bitcoin/bitcoin/blob/master/share/examples/bitcoin.conf)
vincenzopalazzo
CC BY-SA 4.0
2019-08-28T09:00:58.290Z
Thanks, I now understood that bitcoin-cli is a client to bitcoind and bitcoind has to run in server-mode which has to be specified in the config file along with username and password, right?
bomben
CC BY-SA 4.0
2019-08-28T09:05:50.730Z
yes, correct, I have answered inside this post with more [details](https://bitcoin.stackexchange.com/questions/90044/what-role-has-bitcoin-init-as-a-process/90048?noredirect=1#comment103113_90048)
vincenzopalazzo
CC BY-SA 4.0
2019-08-28T09:49:26.953Z
I posted both questions but I don't think they are related. The other question is mainly about `bitcoin-init`.
bomben
CC BY-SA 4.0
2019-08-28T09:51:03.577Z
yes, but include this question.
vincenzopalazzo
CC BY-SA 4.0
2020-09-23T21:31:21.803Z
Assuming your ACLs are in check, you can always use the `includeconf` in your `/home/pi/` config to point to your config file in `/home/bitcoin`.  Then just name the `datadir` option in the `/home/bitcoin` config.  This should allow you to use the `authcookie` without messing with user/pass.  Not that it's cleaner or easier, its just what I do.
Dan
<bitcoin-cli>
Why does bitcoin-cli not know about working directory of bitcoind?
bomben
# Why does bitcoin-cli not know about working directory of bitcoind?

(Asked by: username_0 on 2019-08-28)

I have a /ect/systemd/system/bitcoin.service with the following content and I am wondering, why bitcoin-cli getinfo tells me about a configuration file elsewhere:
error: Could not locate RPC credentials. No authentication cookie could be found, and RPC password is not set.  See -rpcpassword and -stdinrpcpass.  Configuration file: (/home/pi/.bitcoin/bitcoin.conf)

Content of bitcoin.service, especially -conf=/home/bitcoin/.bitcoin/bitcoin.conf:
[Unit]
Description=Bitcoin daemon
After=network.target
[Service]
ExecStart=/usr/local/bin/bitcoind -conf=/home/bitcoin/.bitcoin/bitcoin.conf -pid=/home/bitcoin/.bitcoin/bitcoind.pid
# Creates /run/bitcoind owned by bitcoin
RuntimeDirectory=bitcoind
User=bitcoin
Type=forking
PIDFile=/home/bitcoin/.bitcoin/bitcoind.pid
Restart=on-failure
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true
# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target

**Tags:** bitcoin-cli

> **Comments:**
> **username_1**: bacause it not have the information for the rpc framework, this is an comple example of bitcoin.con, [click me](https://github.com/bitcoin/bitcoin/blob/master/share/examples/bitcoin.conf)  
> **username_0**: Thanks, I now understood that bitcoin-cli is a client to bitcoind and bitcoind has to run in server-mode which has to be specified in the config file along with username and password, right?  
> **username_1**: yes, correct, I have answered inside this post with more [details](https://bitcoin.stackexchange.com/questions/90044/what-role-has-bitcoin-init-as-a-process/90048?noredirect=1#comment103113_90048)  
> **username_0**: I posted both questions but I don't think they are related. The other question is mainly about `bitcoin-init`.  
> **username_1**: yes, but include this question.  
> **username_2**: Assuming your ACLs are in check, you can always use the `includeconf` in your `/home/pi/` config to point to your config file in `/home/bitcoin`.  Then just name the `datadir` option in the `/home/bitcoin` config.  This should allow you to use the `authcookie` without messing with user/pass.  Not that it's cleaner or easier, its just what I do.  

---

## 2 answers

### Answer by username_0 on 2019-08-29. Score: 1 | Accepted answer

`bitcoin-cli` has to be run with the same `user` as `bitcoind`.

Otherwise it will check for the configuration file in the wrong directory, because the **default directory** is the `home` directory of the user the process is run by.


---

### Answer by username_1 on 2019-08-28. Score: 0

The bitcoin-cli use the bitcoin-rpc, so for used a bitcoin-cli, you must ran the bitcoind with the configuration and when it is OK, you can get command with the bitcoin-cli
A simple file configuration could be it
##
## bitcoin.conf configuration file. Lines beginning with # are comments.
##
# On client-side, you add the normal user/password pair to send commands:
rpcuser=alice
rpcpassword=bob

or you can run the bitcoind with this command bitcoind -rpcuser=alice -rpcpassword=bob


---

