How to replace Bitcoin, counterparty server, client passwords in one go (Bash)

  • It is possible to set the same password for everything (bitcoin.conf, server.conf, client.conf)
  • If you do this and have consistent passwords across these three, you can use this command to replace the string across the board (in all /home/USER subdirectories) with a simple command:
xcp@server:~/test$ cat .bitcoin/bitcoin.conf
xcp@server:~/test$ find ./ -type f -name "*.conf" -exec sed -i 's/1234/abcd/g' {} \;
xcp@server:~/test$ cat .bitcoin/bitcoin.conf
xcp@server:~/test$ cat .config/server.conf

xcp@server:~/test$ cat .config/client/client.conf
  • find ./ -type f -name "*.conf" -exec - recursively finds all *.conf files in the current (./) directory and executes sed on them
  • sed -i 's/string1/string2/g' {} \; - performs replacement of string1 by string2 (above we replaced 1234 with abcd)

Note that this works on all *.conf files, including any other which may contain this string, so you need to be careful if you’re have the same password in some other configuration files. You could modify the find command to use specific file names such as below:

$ find . -type f \( -name "bitcoin.conf" -o -name "server.conf" -o -name "client.conf" \)

Remember to stop and then restart all services at the same time (first bitcoin, then counterparty-server) otherwise if only one is restarted, it won't be able to access others.