Mike's Meanderings

Owning my Data - BitTorrent Pi

Who remembers Limewire from the early Aughts?

Limewire was one of the early Peer-to-Peer (P2P) networks out there. It was used mostly to share music files across the Internet. I remember a version of it installed on my high school's network in a secret folder — because back in 2003, educators thought it was a good idea to give high schoolers admin privileges on a network!

Limewire was eventually shut down, but not forgotten:

While Limewire and Napster are gone, their legacy survives today in the form of BitTorrent.

What is BitTorrent? From Wikipedia: "BitTorrent (abbreviated to BT) is a communication protocol for peer-to-peer file sharing (P2P) which is used to distribute data and electronic files over the Internet." Essentially, BitTorrent works by downloading a little bit of a file from everyone in the network who has already downloaded it. This is different from traditional downloading where you pull the entire file from a single server. With BitTorrent you download from several sources simultaneously, which leads to faster downloads.

The moment you start downloading a torrent, you also start to share — the parts you've already downloaded, you begin uploading to others. This is what good torrenters do. When I download an .iso file from Ubuntu or the Raspberry Pi Foundation, I select the torrent option. This takes the burden off their servers and distributes it across other users, saving them bandwidth and money.

So why build a whole Raspberry Pi for this? When you participate in the BitTorrent network, you expose your IP address to everyone connected. If you're interested in privacy, that's a problem. That's where this project comes in.

Today I'm creating a Raspberry Pi torrent box that can always be on and will be hidden behind a VPN. As always, start with a fresh Pi running Raspbian Lite.

Install Deluge

Deluge is a BitTorrent client that facilitates sharing torrents. It has a decent web client you can access through a browser, or you can install a thin client on another computer and control it from there.

sudo apt-get install deluged deluge-web deluge-console

To run the web console:

deluge-web

The default password is deluge. Navigate to http://192.168.1.X:8112 and finish setting it up. Key settings to configure:

  • Network Tab: Check "Use Random Ports"
  • Downloads Tab: Point to folders on your external HDD
  • Daemon Tab: Enable "Allow Remote Connections"

To set up Deluge for remote access from the command line:

deluge-console
sudo nano ~/.config/deluge/auth
# Change: user:password:level
config -s allow_remote True
config allow_remote
exit
sudo pkill deluged

To enable Deluge to run at startup:

sudo nano /etc/rc.local

Add the following before exit 0:

sudo -u pi /usr/bin/python /usr/bin/deluged
sudo -u pi /usr/bin/python /usr/bin/deluge-web

Install ProtonVPN

Next, install a VPN to encrypt torrent traffic and hide your IP address. I chose ProtonVPN as my provider. I trust the folks at Proton Technologies not to keep logs, making it tougher for hackers and/or governments to spy on your data. They're also based in Switzerland, a country with strong privacy laws.

This process must be run as root.

Install the required dependencies:

sudo su
sudo apt-get install openvpn dialog -y

Install the ProtonVPN CLI:

sudo wget 'https://github.com/ProtonVPN/protonvpn-cli/raw/master/protonvpn-cli.sh' -O 'protonvpn-cli.sh' && sudo bash protonvpn-cli.sh --install

Initialize and configure:

sudo protonvpn-cli --init

Follow the prompts:

  • Enter your OpenVPN username and password from your ProtonVPN account
  • Select your ProtonVPN plan
  • Use custom DNS server? Your choice
  • Decrease OpenVPN privileges? Y

Connect to a P2P-supporting VPN node:

sudo pvpn -p2p

Check the status:

sudo pvpn -status

Disconnect before continuing:

sudo pvpn -disconnect

Set Up ProtonVPN as a SystemD Service

To make ProtonVPN easier to start, stop, and run at startup, set it up as a SystemD service:

sudo nano /etc/systemd/system/protonvpn-cli.service

Paste the following:

[Unit]
Description=ProtonVPN CLI Auto-Start
After=network.target

[Service]
Type=forking
User=root
ExecStart=/usr/bin/protonvpn-cli -p2p
ExecReload=/usr/bin/protonvpn-cli --disconnect && /usr/bin/protonvpn-cli -p2p
ExecStop=/usr/bin/protonvpn-cli -p2p
Restart=always

[Install]
WantedBy=multi-user.target

Reboot and you're good to go! Enjoy the modern world of file sharing.

Problems

Honestly, I didn't run into many issues with this project. The programs used are all very stable and well supported.

Resources

💬 Webmentions

No webmentions yet. Be the first to respond!