Bitcoin-cli looking for .cookie file in the wrong directory when using -datadir parameter on bitcoind startup #12289

issue mkyukov opened this issue on January 28, 2018
  1. mkyukov commented at 9:25 PM on January 28, 2018: none

    Description: On Elementary OS Loki 0.4.1 I've downloaded and installed bitcoind as per the official guide from bitcoin.org .

    However, I in my case I don't have enough space on my internal SSD to store the whole blockchain, so I want to download it and maintain it on an external hooked up HDD.

    When I run the bitcoind -daemon -datadir=path_to_external_hdd_folder the Bitcoin server starts up successfully and starts downloading the blockchain to that specified folder (In the logs I can see the height is growing and so is the size of the selected datadir which I passed in as an argument) ..

    Note: My bitcoin.conf file is empty.

    Expected behavior: Expecting for bitcoin-cli to look for the .cookie file withing the pointed -datadir . Occuring behavior: My problem is - when I try to run commands by running bitcoin-cli getblockchaininfo for example, I get the error:

    error: Could not locate RPC credentials. No authentication cookie could be found, and no rpcpassword is set in the configuration file (/home/martin/.bitcoin/bitcoin.conf)

    Steps to reproduce: I can reproduce it every time:

    1. run bitcoind -daemon -datadir=path_to_datadir
    2. wait for bitcoin server to start up
    3. try to run any bitcoin-cli command

    Bitcoin core version and source: The version I'm using is bitcoind 0.15.1 . I installed it through the official bitcoin linux guide.

    System details: The operating system -> ElementaryOS Loki 0.4.1. CPU -> Intel Core i7 (4th Gen) 4720HQ / 2.6 GHz . The hard disk -> External 4TB Seagate HDD

    Extra information: When I move the .cookie file from my external drive to /home/_username_/.bitcoin/bitcoin.conf the commands start working.

    I've tried passing -rpccookiefile=path_to_cookie_file_on_External_hdd to it but that didn't work.

    Setting -rpccookiefile= to the correct path matching the specified -datadir= location does not work.

  2. MarcoFalke commented at 10:05 PM on January 28, 2018: member

    Make sure to pass the same datadir to bitcoin-cli. Otherwise, it can not find the credentials.

  3. MarcoFalke added the label Questions and Help on Jan 28, 2018
  4. MarcoFalke added the label RPC/REST/ZMQ on Jan 28, 2018
  5. mkyukov commented at 7:43 AM on January 29, 2018: none

    So I need to pass the -datadir to every command I invoke with bitcoin-cli?

    Looking at the example bitcoin.conf file from this repo (https://github.com/bitcoin/bitcoin/blob/master/contrib/debian/examples/bitcoin.conf) it states:

    " If no rpcpassword is set, rpc cookie auth is sought. The default -rpccookiefile name is .cookie and found in the -datadir being used for bitcoind. This option is typically used when the server and client are run as the same user."

  6. MarcoFalke commented at 9:07 PM on January 29, 2018: member

    Yes, otherwise it can not find the datadir, i.e. the dir where the cookie file is located.

  7. MarcoFalke closed this on Jan 29, 2018

  8. mkyukov commented at 11:01 PM on January 29, 2018: none

    If this is the intended way for it to work, then the documentation should be updated.

  9. MarcoFalke commented at 11:41 PM on January 29, 2018: member

    @mkyukov Yes it should. Could you please mention where exactly the documentation is outdated? Or even better, propose a pull request yourself.

  10. mkyukov commented at 9:56 PM on February 13, 2018: none

    @MarcoFalke you have a point - I'll do that in the coming days!

  11. tianzongqi commented at 7:58 AM on September 7, 2018: none

    Make sure to pass the same datadir to bitcoin-cli. Otherwise, it can not find the credentials.

    "pass the same datadir to bitcoin-cli" means what? how to handle this?

  12. gunar commented at 10:20 AM on February 25, 2021: contributor

    Passing the datadir

    This is what they mean:

    $ bitcoin-cli -datadir=/var/lib/bitcoind <COMMAND>
    

    Setting up an alias

    You could edit your .bashrc and add

    alias bitcoin="bitcoin-cli -datadir=/var/lib/bitcoind"
    

    and now you can invoke it like this

    $ bitcoin -getinfo
    
  13. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me