Bitmagnet

Bitmagnet is a tool that crawls the Distributed Hash Table (DHT) and attempts in index all known torrents. It’s normally distributed via docker, but you can also deploy without it by installing:

  • VPN
  • Postgres
  • Bitmagnet

VPN

You may want to use a VPN so you don’t get flagged. Even though you’re not downloading files with this tool, it’s a bittorrent tool and that could get you swept up in something.

Postgres

# Insall postgres 
sudo apt install -y postgresql postgresql-contrib

# Create the database
createdb bitmagnet

# Run the psql command as the system user 'postgres' who has superuser rights on the DB
# and set the postgres user password
sudo -i -u postgres psql

ALTER USER postgres WITH PASSWORD 'SOMETHINGRANDOM';
exit

Note - you may need to add a line to the postgres client auth config file. If you can’t connect with psql --host localhost --user postgres --password you may need to add a line like local all all scram-sha-256 to the /etc/postgresql/17/main/pg_hba.conf file.

Bitmagnet

You can install with go as the setup page suggests but they also make a .deb you can more easily install.

wget https://github.com/bitmagnet-io/bitmagnet/releases/download/v0.10.0/bitmagnet_0.10.0_linux_amd64.deb
sudo apt install ./bitmagnet_0.10.0_linux_amd64.deb

Then you can create a service file like this.

sudo vi /etc/systemd/system/bitmagnet-web.service

[Unit]
Description=bitmagnet Web GUI
After=network-online.target
After=pia-vpn.service
Requires=pia-vpn.service

[Service]
Type=simple
User=root
WorkingDirectory=/opt/bitmagnet
ExecStart=/usr/bin/bitmagnet worker run --all
Environment=POSTGRES_HOST=localhost
Environment=POSTGRES_PASSWORD=postgres
Environment=TMDB_API_KEY=theTmdbKey
Restart=on-failure

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload

sudo systemctl enable --now bitmagnet-web.service

To ensure you bind to the VPN address, you may consider a complicated ExexStart as below.

[Unit]
Description=bitmagnet Web GUI
After=network-online.target
# Use whatever service your VPN runs as, though this is a bit unreliable
After=pia-vpn.service
Requires=pia-vpn.service

[Service]
Type=simple
User=root
Environment=POSTGRES_HOST=localhost
Environment=POSTGRES_PASSWORD=postgres
Environment=TMDB_API_KEY=theTmdbKey

# Instead of the normal start, wait 30 sec and bail if no VPN
# We're looking for "dev pia" so adjust as needed
#ExecStart=/usr/bin/bitmagnet worker run --all
ExecStart=/bin/sh -c '\
  SECONDS=0; \
  while [ $SECONDS -lt 30 ]; do \
    VPN_IP=$(ip -4 addr show dev pia | awk '\''/inet / { split($2,a,"/"); print a[1] }'\''); \
    [ -n "$VPN_IP" ] && break; \
    sleep 1; \
  done; \
  if [ -z "$VPN_IP" ]; then \
    echo "Could not get VPN IP on pia interface" >&2; exit 1; \
  fi; \
  echo "Starting client bound to IP $VPN_IP"; \
  export BITMAGNET_DHT_BINDADDRESS=${VPN_IP}:6881 ; \
  exec /usr/bin/bitmagnet worker run --all  \
'

Restart=on-failure

[Install]
WantedBy=multi-user.target

Last modified April 1, 2026: misc change (523640e)