DIY Linux Transmission Server

 

One of my favourite things about Linux is its ability to transform a formerly useless elderly computer into something really useful indeed. This is the first in a series of posts covering some great projects to breathe new life into old machines using Linux.

What’s the Project?

BitTorrent is a fantastically useful distribution mechanism – when downloading updated Linux distro ISOs, it regularly exceeds the speeds available through centralised (HTTP/FTP) download repositories, and the sharing of bandwidth and ease of distribution are a great fit for online communities and fan groups (Zappateers, for example). Unfortunately, BitTorrent tends to be a total disk I/O hog, constantly reading and writing tiny chunks of file all over your disk. This causes big slowdowns for all other running programs which need access to your hard disk, not to mention the stress it puts on the drive itself.

We’re going to use an old computer, GNU/Linux and the Transmission BitTorrent client to offload this resource-intensive process to a networked machine, freeing up your main machine to get on with business unfettered. Sacrificing convenience, however, is not an option. Therefore, we’re going to implement the following convenience features:

  • Administering the client through a web browser
  • Sharing content over the local network
  • Creating a zero-setup process for starting new transfers

Ingredients

Here’s what we’re going to be using for this project:

  • Ubuntu Linux Server Edition
  • PuTTY (If you’re a Windows user)
  • An old x86-based computer
  • An ethernet connection

You don’t need to worry too much about the specs of the computer you’re using, and even notebooks are okay (in this example I’m using a 6 year old Dell Inspiron 2200 with 256MB of RAM and a Celeron M).

1: Ubuntu Server Installation

Follow this link to the download page for Ubuntu Server edition and download the latest available version (11.04 at time of writing). Canonical’s default recommendation is 64-bit which is unlikely to be compatible with older hardware, so make sure to download the 32-bit version if you’re unsure of whether your machine is 64-bit capable.

When the ISO file has downloaded, burn it to a CD and insert it into the target machine. Before booting, make sure that the machine is connected to your network using ethernet. Boot the computer from the CD and select ‘Install Ubuntu Server’.

The first stages of Ubuntu Server setup relate to keyboard detection and location, so set these according to your locale and hardware. Then, wait while the installer configures itself on the LAN.

i: Hostname

The hostname is the name your machine will take on the network. For the sake of ease, I’m going to call the machine ‘Transmission’.

ii: Partition Disks

Because this server only needs to perform one task, we can use the entire disk for the installation – there’s no need for anything more complex in this case.

Select ‘Guided – use entire disk’ from the menu, and then choose the disk you wish to install to at the next prompt. As with any formatting operation, just be triple sure you don’t want any of the data on the target disk before continuing.

If everything is to your satisfaction, review and confirm the changes and write the partition information to disk. The installer will now load the base system to your machine (this might take a few minutes, so grab a cup of coffee).

iii: Configure Users

Our system is only going to have two accounts – an administrator account for the actual user, and a second account under which Transmission can run. We’ll deal with Transmission later on, so when you’re prompted for your information by the installer set up the account using your own information. (For this example, we’ll be using the username randymarsh.)

The installer will create your username and begin the next phase of setup: loading packages.

iv: Package Selection

Before the package selection process starts, you may be asked about automatic updates. Because this server won’t be running anything ‘mission-critical’, you can decline the automatic updates when they are offered. After this, the software selection screen will present itself.

This is where you tell the installer what type of server you want to run. As you can see, there are a few different usage scenarios presented, two of which match our specifications – Samba File Server (for cross-platform network file access) and OpenSSH (for remote administration). Select these and press continue.

v: GRUB

The GRUB boot loader needs to be installed onto the MBR of the machine, so when you are presented with the option to install it select ‘Yes’. Once the boot loader is installed, installation of the server is complete! Eject any media from the drives when prompted and press ‘continue’ to reboot when prompted.

2: Install Transmission

When your server reboots after installation, it’ll be (almost) ready for use. Before we get to installing Transmission, its important to take a note of the server’s IP address. This will (hopefully) be the last time you need to physically interact with the machine itself. At the login prompt, enter your username and password to gain access to the system.

i: Get the IP

As you can see, the IP address for the system is actually listed (10.0.2.15) in the Message of the Day. Write it down and log out by typing ‘exit’ at the prompt. Disconnect the screen, shut the lid of the laptop, unplug the keyboard etc… leaving only ethernet and power plugged in – your computer is now a headless server.

If the IP doesn’t appear in the MOTD, we need to run the ‘ifconfig’ command. The address will be listed as ‘inet addr: 111.222.33.44’. (It’s likely to be in the ‘192.168.*.*’ range, if you’re running on a home network.)

At this stage, log in to your router and make sure that the server is always assigned the same IP address.

ii: Remote Login

Next, we need to log in to the machine remotely. Remember installing the OpenSSH server earlier on? Now its time to kick it into action. If you’re using a Macintosh or Linux machine, open a Terminal window. If you’re using Windows, open PuTTY.

*nix users, enter the following command at the prompt (where randymarsh is your username and 10.0.2.15 is the server’s IP):

$ ssh randymarsh@10.0.2.15

PuTTY users, just enter the IP address of the server and press connect.

You will now be asked to enter your password to complete the login process, after which you’ll be returned a command prompt.

iii: Download and Install Transmission

There are two Transmission components we need to download and install – the CLI and daemon. Both are in the common Ubuntu repositories, so can be installed using apt. Enter the following two commands to install:

$ sudo apt-get install transmission-cli

$ sudo apt-get install transmission-daemon

You will need to enter your login password again to run commands as root, and may be prompted to confirm the download (“Do you really want to use up 3MB of disk space?”).

The daemon will probably autostart at this point, so be sure to kill it so it doesn’t mess up our configuration process:

$ sudo killall transmission-daemon

iv: Create the Transmission User

We’re going to run Transmission under its own username, which means creating a new account. Enter the following:

$ sudo adduser --disabled-password transmission

This creates a new user called ‘transmission’ with password access disabled. A home folder (/home/transmission/) will also be created. You may be prompted to confirm the new user’s ‘personal details’ (name, room number etc…) which you can leave blank.

v: Create a Download Folder

The new user ‘transmission’ has its own home folder, and we’re going to place download files within it. Because the following commands all require root access, its quicker to login as root by using:

$ sudo -s

First, make a folder at /home/transmission/ called ‘downloads’:

$ mkdir /home/transmission/downloads/

Because we’re sharing the folder, we’re going to set it to be something of a ‘free-for-all’ by disowning it and granting RW access to all users:

$ chown nobody:nogroup /home/transmission/downloads

$ chmod 777 /home/transmission/downloads

3: Share the Folder

This is the final ‘extra’ we need to get sorted before we can finally start configuring and using Transmission. Using Samba, we’re going to share the contents of the download folder over the LAN, allowing network users to simply start transfers and access files already completed.

Make sure you’re still logged in as root (if not, use ‘$ sudo -s‘ again).

i: Stop Samba

At the command prompt:

$ smbd stop

ii: Edit the Samba Configuration File

Samba is configured by the ‘smb.conf’ file, which lives in the /etc/samba directory. It has many advanced options, most of which are detailed in the sample smb.conf, however the sharing setup we need is very simple, so we’re going to move the existing configuration file and create our own:

$ mv /etc/samba/smb.conf /etc/samba/smb.conf.old

Now we can create our own smb.conf in place of the old configuration file using GNU nano:

$ nano /etc/samba/smb.conf

GNU nano will open a blank document, ready for you to define your own configuration. An example settings file is below:

[global]
workgroup = randy
security = user
encrypt passwords = yes


[transmission]
comment = Transmission Network Server
path = /home/transmission/downloads
writeable = yes
valid users = randymarsh
public = no

With this configuration, only the user ‘randymarsh’ will be able to access the share. The share will not be ‘advertised’, so you’ll need to remember its name to gain access. Substitute your own username into this configuration file on your machine and press ‘CTRL-O’ to save.

iii: Restart Samba

At the command prompt:

$ smbd start

4: Configure Transmission

Finally we’re ready to actually use Transmission itself! All that preparation is well worth it though – if everything is done correctly, you’ll likely never have to log back into this server again.

The following stages need to be performed as the user ‘transmission’. To switch user:

$ sudo su transmission

(Note that if you are already root then you needn’t issue the sudo command.)

i: Point the Daemon at the Config Files & Launch

Like most (all?) Unix daemons, Transmission employs a user editable configuration file to dictate its behaviour. With the following command, the daemon is instructed to look in the folder /home/transmission/.config/transmission-daemon/ for configuration data. Because this folder doesn’t exist, we need the Transmission daemon to create it and populate it with a default configuration file.

$ transmission-daemon -g /home/transmission/.config/transmission-daemon/ -f

Transmission will now launch in a kind of ‘verbose’ mode. Once it has dumped some information to the terminal, you can close it with CTRL-C.

ii: Edit the Configuration File

Now that the configuration file has been created, we can change the settings to suit our needs. At the command prompt:

$ nano ~/.config/transmission-daemon/settings.json

There are many configuration options available with the Transmission CLI, most (but not all) of which are listed in this file. There are a few specific changes we need to make to the default configuration to suit our needs.

iia – Speed Limits

Scroll to the lines starting at “speed-limit-down”. If you wish to enforce speed limits, up or down, change the default values (100 for each) to the limit you want to impose. Values are in KB/s. To enable or disable the limits, change their boolean value to either ‘true’ or ‘false’.

iib – Working Directories

Transmission requires two working directories – the download directory (where you want the files to end up) and the incomplete directory (where the partial files are stored whilst being downloaded). These are dictated on the “download-dir” and “incomplete-dir” lines of the configuration file.

You should set these folders both to “/home/transmission/downloads” – make sure to check the capitalisation as these values are case sensitive.

iic – Blocklist

It’s always important to block ‘bad’ peers from connecting to your computer for personal security reasons. Change the value of “blocklist-enabled” to true and alter “blocklist-url” to equal “http://www.bluetack.co.uk/config/level1.gz”.

iid – Remote Admin

Remember when I said we weren’t going to have to ever touch the command line on this machine again? That’s what the Transmission Web Admin panel is for.

“rpc-enabled” should be true by default, however we need to add local network users to the whitelist so we can access it within our domain. Change the “rpc-whitelist” value from “127.0.0.1” to “127.0.0.1, 192.168.x.*”, where ‘x’ will likely by either 0 or 1 depending on your network configuration. (If your IP address is 192.168.0.12 then ‘x’ will be 0, whereas if your IP is 192.168.1.14 ‘x’ should equal 1.)

iie – Watch Folder, Clean Up

Finally, we need to tell Transmission to watch for new .torrent files and add them automatically. To this end, we need to add some instructions to the end of the config file. Remember that each line except the last needs to end with a comma, so add one to the last line of the file (“upload-slots-per-torrent”) and then append the following:

"watch-dir": "/home/transmission/downloads",
"watch-dir-enabled": true

Change “trash-original-torrent-files” to true and press CTRL-O to save and quit.

iii: Launch Transmission

At the command prompt:

$ transmission-daemon

Now we can quit the SSH session and exit Terminal.app/PuTTY/etc… and at last get started using the thing.

5: Client Setup

Through this configuration, we are now able to operate the remote Transmission instance completely independently of its host machine. There’s a couple of really cool things we can now do.

Connect to the Download Folder

On your client machine, connect to the Samba share of the download folder. On a Mac, use “Go -> Connect to Folder”, while Windows users can use “Map Network Drive”. Linux setup will vary from desktop to desktop, GNOME users can connect to a network share in the “Places” menu.

You will need to connect using your username and password – randymarsh in the case of this example.

Start a Transfer

Because Transmission is looking at the folder we shared using Samba, all you need to do to start a transfer is copy a .torrent file to that folder (using the connection we established in the previous step). Transmission will automatically start downloading the file into the shared folder when the .torrent is added.

Connect to the Web Interface

With the configuration we set up, the Transmission web interface is available to anybody on the local network. To access it, open a web browser and connect to the IP of the server on port 9091. For example, if your server was on 192.168.0.15, you would type the following into your browser’s address bar:

http://192.168.0.15:9091

The web interface is almost identical to a native Transmission client and allows you to add, remove and pause transfers as well as inspecting them in detail and enabling/disabling speed limited modes.

Conclusion

This use case is a great example of how powerful Linux is as a platform, and its great effectiveness when using just a couple of extra pieces of software (Samba and Transmission). Through this solution, you needn’t worry about tearing the disk on your main machine to pieces and slowing it to a crawl just to seed to your community. In fact, this method is even more convenient than running a native client, too – all that’s required to start a transfer is a simple Finder or Explorer operation.

Hopefully some of you can dust off an old machine headed for the trash and start using it again with these techniques. Enjoy!

2 Responses to “DIY Linux Transmission Server”

  1. Mahyar says:

    Very nice write-up.

  2. Joseph says:

    Thank you for this fantastic tutorial! I look forward to being able to initiate torrents from my phone now.
    I do have a question, I tried placing the samba and transmission directory in a folder located on a web server in the hopes that I could view the files through samba or through the web but I got a 403 error saying that the folder was forbidden. Is this because higher directories were forbidden? I hope I can hear back from you! Thanks again. – Joseph

Leave a Reply