⚙️ Set Up Bitcoin Knots as a systemd Service
1. Create a dedicated user (optional but recommended)
sudo adduser --disabled-password --gecos " " bitcoin
Give the bitcoin
user ownership of your .bitcoin
directory:
sudo mkdir -p /home/bitcoin/.bitcoin
sudo chown -R bitcoin:bitcoin /home/bitcoin/.bitcoin
Move your bitcoin.conf
file there if needed.
2. Create a systemd service unit
Create the service file:
sudo nano /etc/systemd/system/bitcoind.service
Paste the following contents:
[Unit]
Description=Bitcoin Knots daemon
Documentation=https://github.com/bitcoinknots/bitcoin/blob/master/doc/init.md
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/opt/bitcoinknots/bin/bitcoind -daemon \
-pid=/run/bitcoind/bitcoind.pid \
-conf=/etc/bitcoin/bitcoin.conf \
-datadir=/var/lib/bitcoind
PermissionsStartOnly=true
ExecStartPre=/bin/chgrp btc /etc/bitcoin
User=btc
Group=btc
Type=forking
PIDFile=/run/bitcoind/bitcoind.pid
Restart=on-failure
TimeoutStopSec=600
# Secure sandboxing options
RuntimeDirectory=bitcoind
RuntimeDirectoryMode=0710
ConfigurationDirectory=bitcoin
ConfigurationDirectoryMode=0710
StateDirectory=bitcoind
StateDirectoryMode=0710
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
NoNewPrivileges=true
PrivateDevices=true
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target
3. Reload systemd and enable the service
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable bitcoind
sudo systemctl start bitcoind
systemctl status bitcoind
You should see something like:
Active: active (running)
If you compiled bitcoind
into a non-standard path, adjust ExecStart
accordingly.
Make sure bitcoin.conf
has proper permissions (chmod 600
) and is owned by the bitcoin
user.
Logs are available via journalctl
:
journalctl -u bitcoind -f