If, like me, you use a Raspberry Pi as a multimedia centre it’s really handy being able to kick off a torrent without having to be logged into the Pi. This is especially useful if you want to download something using your phone, to your Pi, from literally anywhere.
Here’s how to configure Transmission so you can download torrents to your Pi from anywhere.
First up lets install Transmission and Apache.
sudo apt-get update sudo apt-get install transmission-daemon apache2
Now lets make sure it is enabled:
root@pi:~# grep ENABLE /etc/default/transmission-daemon ENABLE_DAEMON=1
If that is not set to ‘1’ then edit the file and change it. Next, restart the daemon just to be sure.
sudo service transmission-daemon restart
What you now have is Transmission listening on TCP/9091. If you navigate to your Pi’s IP on that port you should see the web interface (e.g. http://192.168.0.100:9091/)
If you see the interface above then we’re off to a good start!
The keen eyed amongst you will notice that no authentication was required to see the interface. If we’re going to be making this available on the Internet (so can you can download torrents from anywhere!) then we need to put an authentication layer in front. For this we will use ye auld trusty Apache.
There are two things we need to do.
- Run Transmission behind Apache with a reverse proxy
- Add basic authentication to the location
Lets go ahead and add the relevant stanzas to the Apache config. With your favourite text editor open the config.
vi /etc/apache2/sites-enabled/000-default
Then add our new config options. Replace ‘192.168.0.100’ with your Pi’s IP (or 127.0.0.1 may work).
RewriteEngine on RewriteRule /transmission[/]?$ /transmission/web/ [R=permanent] ProxyRequests On ProxyPreserveHost Off <Location "/transmission"> ProxyPass "http://192.168.0.100:9091/transmission" ProxyPassReverse "http://192.168.0.100:9091/transmission" Order allow,deny allow from all AuthUserFile /var/www/.htpasswd AuthName "Transmission" AuthType Basic </Location>
Next we create the authentication file.
sudo htpasswd -c /var/www/.htaccess user1 New password: Re-type new password:
This now means you need to log in with ‘user1’ and your chosen password to be able to access transmission.
Last step for this configuration is to enable the required Apache modules and restart.
sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod rewrite sudo service apache2 restart
If you now browse to your Pi’s IP in a web browser (not using port 9091 this time but instead specifying /transmission/) you should see a login prompt and after logging in, see the same Transmission interface as before.
if you haven’t already got Apache port forwarded through your router you need to forward port 80 to the Pi’s IP.
Do not forward port 9091 or you defeat the whole purpose of this!
Of course it is probably worth while enabling SSL so at least your password isn’t sent unencrypted. There are plenty of articles on the Interwebs explaining how to do this.
Finally you may wish tweak some Transmission settings. Click the wee spanner symbol at the bottom of the Transmission page and at the very least specify:
- Maximum upload Limit (so you don’t rip the arse out your upload bandwidth)
- The path which torrents download to (for me that’s an external drive attached to the Pi)
- The maximum number of allowed Peers (100 per torrent, 500 maximum?).
- Set the ‘stop seeding ratio’ to something sensible incase you forget you remove the torrent from Transmission. Otherwise if you download something and forget about it you could find yourself seeding for weeks. 50% is pretty generous.
It’s worth mentioning Transmission has a configuration file located at
/etc/transmission-daemon/settings.json
However, this file is written when the transmission-daemon exits cleanly so any changes you make will be over written. You can therefore only edit this file when the daemon is not running.
That’s all folks – have fun!