8. Installing a Bittorrent Client
I don’t know about you, but I want to install a Bittorrent client on your Pi, and I’ll tell you why. If your PC uses a wireless router and you use Bittorrent, you will probably find that the Bittorrent traffic over your network utterly clobbers your PC’s connection, making the internet virtually unusable. You also have to leave your PC on overnight when downloading large files, like Linux distributions or the many legal video torrents that exist. Furthermore, once your torrent has finished, you have to leave the bandwidth-hogging Bittorrent program running in order to get any sort of honourable ratio.
Running a Bittorrent client on your Pi, plugged directly into the router, solves all these problems. In fact, the whole setup is so unobtrusive that I’ve occasionally forgotten I’ve been seeding something and discovered I’ve worked up an enormous ratio. Fnar fnar. Sorry. It also allows something else – you can log into your bittorrent client from any PC, even from outside your home network. Say you are at work, browsing around at lunchtime, when you remember there is a perfectly legal film you want to watch this evening.  Logging in from your work’s PC, you can tell your Pi to start downloading it and by the time you get home, your film will be waiting for you.
So let’s find a Bittorrent client to install. Shall we fire up Google? No. We don’t need to do that. We can search the repository for Bittorrent clients using the “apt-cache” command like this: apt-cache search bittorrent client. Note that you don’t need to sudo it because you aren’t installing anything yet. The “apt-cache search” bit searches for whatever you put after it.
naich@raspberrypi ~ $ apt-cache search bittorrent client apt-transport-debtorrent - an APT transport for communicating with DebTorrent aria2 - High speed download utility azureus - BitTorrent client ... loads and loads and loads ... transmission - lightweight BitTorrent client transmission-cli - lightweight BitTorrent client (command line programs) transmission-common - lightweight BitTorrent client (common files) transmission-daemon - lightweight BitTorrent client (daemon) transmission-dbg - lightweight BitTorrent client (debug symbols) transmission-gtk - lightweight BitTorrent client (GTK interface) transmission-qt - lightweight BitTorrent client (Qt interface) unworkable - efficient, simple and secure bittorrent client vuze - Multimedia BitTorrent client naich@raspberrypi ~ $
Spoiled for choice, aren’t we? What we want is one that will happily do its own thing without any input from a human and doesn’t need a GUI. In Linux, a program that runs in the background without requiring human interaction is called a “daemon”. If you take a look at the list, two packages fit the bill – “deluged” and “transmission-daemon”. We’ll use the latter. Let’s download it, install it, set it up, and run it with 4 words: sudo apt-get install transmission-daemon.
naich@raspberrypi ~ $ sudo apt-get install transmission-daemon Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libcurl3-gnutls libminiupnpc5 libnatpmp1 minissdpd transmission-cli transmission-common Suggested packages: natpmp-utils transmission-gtk The following NEW packages will be installed: libcurl3-gnutls libminiupnpc5 libnatpmp1 minissdpd transmission-cli transmission-common transmission-daemon 0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded. Need to get 1,905 kB of archives. After this operation, 4,173 kB of additional disk space will be used. Do you want to continue [Y/n]?
Do you see all those dependencies that will be installed as well? Apt is also suggesting other packages that aren’t needed but might be useful. You want to continue. Things going up the screen… Done yet? Did you notice this line?
[ ok ] Starting bittorrent daemon: transmission-daemon.
You are now running your bittorrent client. It will automatically start up every time your Pi starts, so you don’t even have to remember to restart it when you reboot. Isn’t that nice? Come on – that is pretty cool isn’t it?
So let’s use it. Transmission comes with a built in web server to use as an interface. You use it by putting this into your browser: “http://your_pi’s_ip_address:9091″ – that’s a colon and 9091 after the address, no slashes. You should see this:
403: Forbidden
Unauthorized IP Address.
Either disable the IP address whitelist or add your address to it.
If you’re editing settings.json, see the ‘rpc-whitelist’ and ‘rpc-whitelist-enabled’ entries.
If you’re still using ACLs, use a whitelist instead. See the transmission-daemon manpage for details.
This is correct. As a general rule, installed packages will be set up in a safe way, so that nasty people (including you) can’t use it. You will need to edit the configuration file to relax its security enough that you can use it. Full instructions on how to do it are here: https://trac.transmissionbt.com/wiki/EditConfigFiles but let’s just get it going quickly for now. Transmission is a bit unusual in that it overwrites its configuration files when it exits. This isn’t normal and caused me much confusion for a while because I’d edit the configuration, restart Transmission and it wouldn’t work because all my changes were overwritten. So let’s stop Transmission before we edit the file with sudo service transmission-daemon stop:
naich@raspberrypi ~ $ sudo service transmission-daemon stop [ ok ] Stopping bittorrent daemon: transmission-daemon. naich@raspberrypi ~ $
You can probably work out what is going on there. Now edit the configuration file. It’s in the “/etc” directory, (along with all the other configuration files), in its own directory. If you want to find a configuration file for a daemon, look in “/etc” – it’ll be there, either in its own directory or as a file. Type sudo nano /etc/transmission-daemon/settings.json:
naich@raspberrypi ~ $ sudo nano /etc/transmission-daemon/settings.json
Now, move the cursor down until you find this part (without the numbers):
1 "rpc-authentication-required": true, "rpc-bind-address": "0.0.0.0", "rpc-enabled": true, 2 "rpc-password": "{1669ab9b7fdadc2a8a910abf75a60f6c584365e6oRs3weiW", "rpc-port": 9091, "rpc-url": "/transmission/", 3 "rpc-username": "transmission", 4 "rpc-whitelist": "127.0.0.1", 5 "rpc-whitelist-enabled": true,
“rpc” means “Remote Procedure Call” and refers to the web server. Â Seems a bit odd to call it this as RPCs are generally from computers rather than humans, but what do I know? Â When you make changes, make sure you preserve the punctuation: the quotes, colons and commas all need to be in their correct places. Â Going through the numbers, leave the unmarked lines alone and change these ones to suit your preferred method of access:
- If this is “true” (note that there are no quotes round the word in the config file) then you will be asked for a username and password before you can use the web pages.
- This is the password you log in with if 1. is set to “true”. Â The default is an impossible-to-guess huge random string.
- The username you log in with if 1. is set to “true”. Default is “transmission” and you should change it if you plan to use a username/password – default usernames are bad.
- The comma-separated list of IP addresses that are allowed to use the web page. Â A “*” means any number. Â If your home network has addresses that all start “192.168…” then you could make this string “127.0.0.1,192.168.*.*” to make sure that only people in your home network can log in. Â Leave the “127.0.0.1” in there, as this refers to the Pi itself.
- If you set this to “false” then 4 is ignored and anyone can connect from any PC.
I’d recommend either:
- Set 1 to “false”, 5 to “true” and make sure that any PC you will access it from is included in the list at 4 or
- Set 1 to “true”, set the name/password in 2/3 and set 5. to “false”
The first one doesn’t require a password, but you will be restricted to logging in from only the PCs whose IP numbers are specifically set in 4. Â The second allows you to access it from any PC in the world (make sure you set your router’s port forwarding so connections to port 9091 are sent to your Pi’s IP), but you need to have a username/password to stop any Tom, Richard or Harry using it.
Then start it up again with  sudo service transmission-daemon start:
naich@raspberrypi ~ $ sudo service transmission-daemon start [ ok ] Starting bittorrent daemon: transmission-daemon. naich@raspberrypi ~ $
Point your web browser at http://your_pi’s_address:9091 and you should see something like this:
But probably not as squished.  I wanted to get all the icons in the screenshot. But let’s not wander away from the point that you now have a working Bittorrent client on your Pi. Give yourself a pat on the back and put the kettle on for a celebratory cup of tea.
But there is a slight problem. Click on the spanner and look at “Download to:” to see where your torrents will be put. It’s something like “/var/lib/transmission-daemon/download/buried/so/deep/youll/never/find/it/again/”. Wouldn’t it be better to have it somewhere a bit more memorable, maybe even on a memory stick so you could take it out of your Pi and take it with you? We can do both. Change the “Download to: ” location to /mnt/downloads and continue to the next chapter, where we’ll be setting it all up…
Great guide. Really. But Im having a problem. I lose connection to transmission after like 20 minutes or so. And I have to unplug the power and plug it in again to be able to reconnect to it. What can be wrong?
It is probably the Pi being overwhelmed by the Bittorrent traffic. I find that this often happens once you have connected to a few peers. All the networking resources are being used for the torrents, leaving virtually nothing for anything else, making it look as if the Pi has locked up. Have a look at the bottom of the next page to see how to restrict the speed and number of connections.
Ohh it seems to be right, If I restrice the connection to peers it works fine. evan thought it kind of suck not being able to be connected to as many as possible… Thx for the reply
Have you had any success with using the watch-dir? My issue is that it sees the file but never loads it into the download list. Also fantastic blog!
Syslog
Nov 8 08:47:24 raspberrypi transmission-daemon[2134]: Found new .torrent file “2F6BACB57691478B6C122F625A0F0C76A0B263CA.torrent” in watchdir “/home/pi/watch” (watch.c:92)
Permissions
drwxrwxrwx 2 pi debian-transmission 4096 Nov 8 08:17 watch
Sorry, never used that bit of it Neal. Has the file got permissions for transmission-daemon to read it?
this is useful. nice work bro. thanks so much.
When I try to stop transmission-daemon I get [info] Usage: /etc/init.d/transmission-daemon {start|stop|reload|force-reload|restart|status}. I tried to proceed to change the settings, opting for the username and password option, I then attempted to restart it with the same info message, when I point my browser towards it I still get 404. Any ideas?
It’s not stopping. The info message means it’s not understanding the command you are giving it. Are you using upper case letters or maybe cutting and pasting the “:” at the end of the line? You could also try
sudo /etc/init.d/transmission-daemon stop
which is and alternative to the “sudo service transmission-daemon stop” command.
how do I make a static connection via WiFi? Its working pretty good now, but its still dynamic. My /etc/network/interfaces now looks like this:
auto lo
iface lo inet loopback
auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wireless-power off
wpa-ssid “xxxxx”
wpa-psk “xxxxx”
iface default inet dhcp
Bob – the line “iface wlan inet dhcp” should be changed in the same way as for a wired connection, as described here – http://naich.net/wordpress/?p=457
Hi,
my transmissions server wont download faster then 5Kp/s. the port is open, and internet works with everything except the transmissions-daemon. any help would be apreciated 🙂
Make sure your tortoise icon isn’t enabled (that slows down the transfer rate) and that it is set to something sensible in the settings (gear icon) and that the limits are not too low in the “preferences” (spanner icon).
the tortoise icon is off, and there are no limitations on the download speeds in the gear or spanner menus. but still it refuses to go anywere near decent down speeds
If everything else on the Pi works at the correct speed then the problem could be your ISP throttling P2P traffic. Many ISPs do this during peak usage hours, so you could try leaving it overnight and see if it speeds up in the early hours of the morning.
hi, you were right. i noticed that this morning as someone else suggested this to me. thanks for your help. 🙂
Thanks for an excellent guide. Is there any way to keep the .torrent files somewhere other than in /var/lib/transmission-daemon/info/torrents? I don’t want to keep data files on the SD card especially as I have about 300 torrents available for seeding. Ideally they would be on my external hard disk. I think I might have to experiment with links
>>Is there any way to keep the .torrent files somewhere other than in /var/lib/transmission-daemon/info/torrents?
I have now got the answer to this problem. A gentleman who goes by the handle of Timelord1 was kind enough to provide it to me on another forum.
“Simplest way of going about this would be to create new config files where you want them. In terminal execute:
transmission-daemon -g [path-to-config]
Kill the daemon and edit the settings file. After which, you will always need to start it pointing to that location, for example:
transmission-daemon -g /mnt/torrents/.config/transmission-daemon”
It seems a simple and elegant solution.
Brilliant – thanks so much for this, would have got nowhere with my Pi without this great blog