Skip to content

Instantly share code, notes, and snippets.

@rupertlssmith
Last active July 7, 2025 20:14
Show Gist options
  • Save rupertlssmith/442c9c062536a9ec4b126a0e743cdcb4 to your computer and use it in GitHub Desktop.
Save rupertlssmith/442c9c062536a9ec4b126a0e743cdcb4 to your computer and use it in GitHub Desktop.

Revisions

  1. rupertlssmith revised this gist Jun 14, 2025. 1 changed file with 31 additions and 7 deletions.
    38 changes: 31 additions & 7 deletions service.md
    Original file line number Diff line number Diff line change
    @@ -27,21 +27,45 @@ sudo nano /etc/systemd/system/bitcoind.service

    Paste the following contents:

    ```ini
    ```
    [Unit]
    Description=Bitcoin Knots daemon
    After=network.target
    Documentation=https://github.com/bitcoinknots/bitcoin/blob/master/doc/init.md
    After=network-online.target
    Wants=network-online.target
    [Service]
    ExecStart=/usr/local/bin/bitcoind -daemon -conf=/home/bitcoin/.bitcoin/bitcoin.conf -pid=/home/bitcoin/.bitcoin/bitcoind.pid
    ExecStop=/usr/local/bin/bitcoin-cli stop
    User=bitcoin
    Group=bitcoin
    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=/home/bitcoin/.bitcoin/bitcoind.pid
    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
  2. rupertlssmith revised this gist Jun 14, 2025. 1 changed file with 86 additions and 0 deletions.
    86 changes: 86 additions & 0 deletions service.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    ## ⚙️ Set Up Bitcoin Knots as a systemd Service

    ### 1. Create a dedicated user (optional but recommended)

    ```bash
    sudo adduser --disabled-password --gecos "" bitcoin
    ```

    Give the `bitcoin` user ownership of your `.bitcoin` directory:

    ```bash
    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:

    ```bash
    sudo nano /etc/systemd/system/bitcoind.service
    ```

    Paste the following contents:

    ```ini
    [Unit]
    Description=Bitcoin Knots daemon
    After=network.target

    [Service]
    ExecStart=/usr/local/bin/bitcoind -daemon -conf=/home/bitcoin/.bitcoin/bitcoin.conf -pid=/home/bitcoin/.bitcoin/bitcoind.pid
    ExecStop=/usr/local/bin/bitcoin-cli stop
    User=bitcoin
    Group=bitcoin
    Type=forking
    PIDFile=/home/bitcoin/.bitcoin/bitcoind.pid
    Restart=on-failure
    TimeoutStopSec=600
    RuntimeDirectory=bitcoind

    [Install]
    WantedBy=multi-user.target
    ```

    ---

    ### 3. Reload systemd and enable the service

    ```bash
    sudo systemctl daemon-reexec
    sudo systemctl daemon-reload
    sudo systemctl enable bitcoind
    sudo systemctl start bitcoind
    ```

    ---

    ### 4. Check service status

    ```bash
    systemctl status bitcoind
    ```

    You should see something like:

    ```
    Active: active (running)
    ```

    ---

    ### ✅ Notes

    - 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`:

    ```bash
    journalctl -u bitcoind -f
    ```

  3. rupertlssmith renamed this gist Jun 14, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. rupertlssmith created this gist Jun 14, 2025.
    69 changes: 69 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    # 🧩 Bitcoin Knots Installation Guide (Debian)

    ## 1. Install Required Dependencies

    ```bash
    sudo apt update
    sudo apt install build-essential libtool autotools-dev automake pkg-config bsdmainutils curl git
    sudo apt install libssl-dev libevent-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libboost-thread-dev
    sudo apt install libminiupnpc-dev libzmq3-dev libsqlite3-dev
    ```

    ## 2. Clone the Bitcoin Knots Repository

    ```bash
    git clone https://github.com/bitcoinknots/bitcoin.git
    cd bitcoin
    ```

    ## 3. Checkout the Latest Stable Release

    ```bash
    git checkout $(git tag | grep 'v[0-9]' | sort -V | tail -n1)
    ```

    ## 4. Build Bitcoin Knots

    ```bash
    ./autogen.sh
    ./configure
    make -j$(nproc)
    ```

    ## 5. Install the Binaries

    ```bash
    sudo make install
    ```

    ## 6. Run Bitcoin Knots

    ```bash
    bitcoind -daemon
    ```

    To check the status:

    ```bash
    bitcoin-cli getblockchaininfo
    ```

    ---

    ## 📁 Optional: Create `bitcoin.conf`

    File location: `~/.bitcoin/bitcoin.conf`

    Example contents:

    ```
    server=1
    daemon=1
    txindex=1
    rpcuser=yourusername
    rpcpassword=yoursecurepassword
    ```

    ---

    Let me know if you want instructions for GUI (`bitcoin-qt`), pruning, or testnet configurations.