Raspberry Pi as Torrent Machine

I wanted to download torrent content and for that, I was not interested to use my PC as most of the time it gets switched off (Due to my day job), and I was looking for uninterrupted download. So I picked up a Raspberry Pi, laying around, and set it up with deluge and VPNBook free VPN. So basically the post is all about how I set it up. Here we will be setting up the deluge daemon and the web UI as well to the raspberry pi. The Deluge daemon can be accessed from the Deluge desktop or web application.

This includes,

  1. Installation of Deluge and its web UI.
  2. VPN Setup (VPNBook)
  3. Setting up shared folder to save downloaded files directly to network shares.
Products Used in this article:-
Install Deluge to Pi:-

To install deluge and the web interface for it type in the following commands to the terminal of the Raspberry Pi. But before running the installation commands, make sure to updtae the apt packages if you have not done in a while. To do so type in
sudo apt update && sudo apt upgrade.

Now use the following commands,

pi@raspberrypi:~ $ sudo apt install deluged deluge-web deluge-console python-mako

The deluged deluge-web part will install the deluge headless version and the web UI for it.  deluge-console helps in invoking console to access the deluge daemon. Ex. deluged deluge-console The final package python-mako is a dependency.

After the installation is done, we need to allow remote access to Deluge. Also, we will be creating a user for Deluge. TO do so we need changes in the deluge configuration file and the installation of deluge does not create the configuration file by default, to create the config file we need to run deluge at least once. That can be achieved by using the command deluged which will create the default configuration file for deluge.

To allow remote access to deluge type in ,

pi@raspberrypi:~ $  deluge-console "config -s allow_remote True"

Now kill deluge using command sudo pkill -i deluged.

For more details check here. Doing so will allow connection to the deluge daemon from any other UI interface such as a different PC. We can add users to the deluge by adding the credential details to the Deluge auth file. Which can be done as follows,

pi@raspberrypi:~ $ echo "<required_user>:<user_password>:10" >> ~/.config/deluge/auth

Ok now deluge is all set and a couple of things are remaining such as adding the folders where the files will be saved and creating services for Deluge and the respective web UI such that they will be triggered when pi boots up and also will take care of crashing as well.

Service for deluged,

sudo nano /etc/systemd/system/deluged.service

Enter the following contents to the created editor,

[Unit]
Description=Deluge Daemon
After=network-online.target #

[Service]
Type=simple
User=pi
Group=pi
UMask=007
ExecStart=/usr/bin/deluged -d
Restart=always
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target

Now press ctrl+x and press Y and hit Enter.

We need to create another service for the web UI, to do so type in,

 

sudo nano /etc/systemd/system/deluge_web_ui.service

and enter the following contents,

[Unit]
Description=Deluge Web Interface
After=network-online.target deluged.service
Wants=deluged.service

[Service]
Type=simple
User=pi
Group=pi
UMask=027
ExecStart=/usr/bin/deluge-web
Restart=always

[Install]
WantedBy=multi-user.target

Now press ctrl+x and press Y and hit Enter.

Now as both services are ready, lets enable them

pi@raspberrypi:~ $ sudo systemctl daemon-reload
pi@raspberrypi:~ $ sudo systemctl enable deluge_web_ui.service
pi@raspberrypi:~ $ sudo systemctl enable deluged.service
pi@raspberrypi:~ $ sudo systemctl start deluged.service
pi@raspberrypi:~ $ sudo systemctl start deluge_web_ui

Now we can check the status of services by using the commands,

pi@raspberrypi:~ $ sudo systemctl status deluged
pi@raspberrypi:~ $ sudo systemctl status deluge_web_ui

Learn more about deluge services here.

delugeui-status.png

delugedstatus.png

 

Now lets access the web ui using the IP address of the Pi and the url is <pi_ipaddress>:8112 instead of Ip_address, hostname can also be used. The default web ui password is deluge.

 

inteface

 

Setting Up Network Share to Pi (Optional):-

I have a OMV based NAS and I wanted to download my files to the NAS (Ofcourse deluge can be installed directly in NAS but I wanted it separately to have isolation). So I mounted a OMV share to the Pi and added the path to deluge. To start adding SMB shares to Pi we first need to install cifs-utils. To do so use the following command,

pi@raspberrypi:~ $ sudo apt-get install cifs-utils

Now lets create a directory where the share will be mounted and and mount it,

 

pi@raspberrypi:~ $ sudo mkdir /mnt/deluge
pi@raspberrypi:~ $ sudo mount -t cifs -o guest //<NAS_SERVER_IP>/<SHARE> /mnt/deluge/

Overhere I have used guest but you can use user=<user_name>,password=<password>, I have allowed guest access to the network share so guest is ok for me othewise if it requires credentials, use username and password.

To mount the share automatically whenever the pi boots up we can use fstab. To do so use the following commands,

pi@raspberrypi:~ $ sudo nano /etc/fstab

Add the following line,

//<NAS_SERVER_IP>/<SHARE>/ /mnt/deluge cifs guest,_netdev,x-systemd.automount 0 0

 

Again over here change guest with proper creds, if rewqired, replace guest with username=<user_name>,password=<password>.

Now open up the deluge web UI by usng the URL <pi_ipaddress>:8112 and got ot preferneces and the folder /mnt/deluge  in Download to option. You can change other folder options too depending upon you requirement and the way you want it to set it up.

 

After rebooting the Pi sudo reboot try to download a file and it should appear in the Network share. For example use the torrent file for Raspbian Lite from Raspberry Pi Downloads page or use any test wesbites like this.

 

Setup VPN:-

So the final part is to install a VPN Client to Pi to make the connections anonymous and being safe. However, I am not sure of how much VPNBook is safe and if it is trustworthy. But anyway as I am going to use OpenVPN it should work with any supported VPN service provider.

 

First install OpenVPN and set it up,

pi@raspberrypi:~ $ sudo apt-get install openvpn
pi@raspberrypi:~ $ cd /etc/openvpn

Now download VPNBook certificates,

pi@raspberrypi:~ $ sudo wget https://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-PL226.zip
pi@raspberrypi:~ $ sudo unzip VPNBook.com-OpenVPN-PL226.zip

Now create a new file passwords.txt and add the VPNBook credentials which has to be updated regualrly and can be found from here.

pi@raspberrypi:~ $ sudo nano password.txt

Add,

vpnbook
<fecthed_password>

Now edit the .ovpn file and the user creds file location,

pi@raspberrypi:~ $ sudo nano vpnbook-pl226-udp53.ovpn

Add the path to passwords.txt file against auth-user-pass like,

auth-user-pass /etc/openvpn/password.txt

Now start openvpn

pi@raspberrypi:~ $ sudo openvpn vpnbook-pl226-udp53.ovpn

Ok, Now thats all with this. Hope it has worked for you. Thanks !!

Related posts

Leave a Comment