How to Create a web-based Torrent Box using AWS and Deluge

Daniel Woods
6 min readJul 4, 2018

--

BitTorrent is a decentralized file transfer protocol that allows for downloaded data to be shared between peers, meaning there is less load on the originating content host. While many people associate BitTorrent with the sharing of illegal content such as pirated Movies/TV Shows, the legitimate uses for the protocol should not be ignored. Blizzard Entertainment (for example) use BitTorrent protocol to reduce the cost of delivering game updates to players. Their game client allows players to download off of their peers instead of directly from Blizzard’s content delivery network, saving Blizzard a tonne of money in data transfer costs.

There are many other pros (and some cons) to using BitTorrent, however that’s what this articles is about. Below, I’m going to show you how you can utilize AWS Lightsail to host a dedicated BitTorrent server. We’re going to use Deluge to download files and MobaXterm to transfer them to a local computer. We’ll also be able to add torrent files and view download progress using the web UI.

Step 1: Create a Lightsail instance

If you’re new to AWS, you’ll need to sign up for an account. AWS is one of the largest providers of cloud computing on the market. To sign up for an account you can click here.

Head to the AWS Lightsail console and spin up a Lightsail instance. Lightsail is an AWS product that aims to compete with the likes of DigitalOcean, when it comes to fixed prices per-month of virtual private servers.

Select your preferred AWS Region and Ubuntu 16.04 as the blueprint. Create an SSH Keypair so that we can connect to the instance. Once the instance has been created, click on the instance in the console and head to the Networking tab. We have two things to do here: 1) Change the IP address to Static 2) Open port 8112.

Below IP Addresses, click the “Create Static IP” button. Assign the newly-allocated IP address to the instance. This ensures that the Instances IP Address never changes, which can occur when the instance is power cycled (stopped and started).

In the “Firewall” section, click the “Add Another” button to add a rule. Create a custom TCP rule for port 8112. Once done, hit Save.

Now that we’ve assigned a static public IP address and opened port 8112, we can now connect to the instance and continue the setup. Grab the Public IP address from the Lightsail console and connect using your preferred terminal emulator. Most people use PuTTY, however for this example, I’m going to use MobaXterm for the very reason that it includes an SFTP client, which we’re going to use to get the tormented files from the instance . Connect to the instance the following commands to update the operating system, upgrade any out-of-date packages and install Deluge BitTorrent Client.

sudo apt-get update; sudo apt-get -y upgrade; sudo apt-get install -y deluged; sudo apt-get install -y deluge-web;

Step 2: Set up the Web UI

Next, let’s configure Deluge’s web UI, so that we can connect and view torrents over HTTP. For this demonstration, we’re going to use Deluge’s default web port (8112) without HTTPS. If you’re in any way security conscious/paranoid, you’ll definitely want to enable HTTPS.

Next, run the following command to initialize the software daemon and configuration files.

deluged; deluge-web -f; sleep 2; pkill deluged; pkill deluge-web

Now let’s set Deluge up as a service. This will let the software automatically start on boot and stay running after the SSH connection has been closed. Open “/etc/rc.local” using nano with the following command:

sudo nano /etc/rc.local

Once you have the file open, add the following lines before the “exit 0” line. Adding them after “exit 0” will cause the commands to not be executed.

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

To exit, press Ctrl+X, followed Y and Enter to write the changes. Once done, reboot the instance in order to see that everything worked out okay.

sudo reboot

Step 3: Connect to the Web UI

In the console, check to see if the Deluge Web UI is running by attempting to connect to it. Paste the following command into the console:

curl 127.0.0.1:8112

The command should return a bunch of HTML. If the command times out, go back and check that you’ve correctly saved the two lines to “/etc/rc.local” before the “exit 0” line.

If all is good, try connecting to the Web UI using a web browser. In the search bar of your favourite browser, enter:

http://YOUR_INSTANCE_IP:8112/

This should allow you to connect to the Deluge console. Enter the default password of “deluge” and update this. Remember that over HTTP, it’s very easy for anyone to see what you’re sending.

Alright so far, so good! Right now, we’ve set up a Deluge BitTorrent daemon and Web UI to interact with. Next, let’s try to add a torrent. Get yourself a .torrent file. For this example, I got a torrent from CentOS, a common Linux distribution.

Add the torrent using the Web UI. If you have a Magnet URL, you can paste it into the URL section of the Add prompt.

Step 4: Getting your Files

To access our files we can use Moba Xterm, the software we used to connect to the server. If you’re using PuTTY or Mac/Linux, you can always use FileZilla instead. In Moba Xterm however, open a connection to the server and select the SFTP tab on the left hand side of the window. This should bring you into ubuntu’s home folder. By default, there will be a subdirectory called “Downloads”. Open this folder to reveal anything that you’ve torrented.

Right-click on any file or folder to download it. You can also drag/drop the file out of the window.

Step 5: Enable HTTPS

I’ve included this step at the end because it’s entirely optional and somewhat pointless. Currently the default settings used by Deluge generate a 1024-bit TLS Certificate that’s signed using MD5. The Web UI uses TLS 1.2 with RSA as a key exchange and AES_128_GCM , all of which provides no forward secrecy and has become obsolete compared to modern standards.

That said, Using the Web UI, we can enable HTTPS by opening the Settings and heading to the Interfaces tab. Here we can specify our own certificates, or use the certificates generated by Deluge. For simplicity, let’s use the insecure ones generated by Deluge.

Tick the “Enable SSL” box and hit Save. Once done, head back to the instance and reboot using the sudo reboot command. We’ll need to edit the URL we use to connect to the instance. Instead of http:// we will need to use https://

https://YOUR_INSTANCE_IP:8112/

Upon reconnecting to the website, you’ll likely be greeted with an HTTPS error relating to the invalid certificate that we’re using with the website. In any other circumstance, we shouldn’t be ignoring this error. However, as we trust our server and will only be torrent public and legal content, we’ll continue.

Confirm the Security Exception and the website will load like before. Now, the connection will use broken HTTPS. If you’d like to improve the security, the next step would be to acquire a valid, trust TLS certificate. This however, would also require a domain name to point to.

And that’s all for now! Enjoy torrenting/downloading Linux distros and open-source software!

--

--