Auto Download Torrent Rapberry Pi

Do your part for the global “Linux distribution network” by building a dedicated, secure, torrent-downloading megalith that barely uses 10W of power. It is possible, and it will, of course, be based on a Raspberry Pi.

Installing and using pyLoad Download Manager on Raspberry Pi. Installing and using pyLoad Download Manager on Raspberry Pi. Submitted by Deepesh Agarwal on Sun, - 05:12. Free Download Manager. Download Manager. After installing transmission torrent client on Raspberry Pi. Using web client, I can start and stop and download torrents within the local network and, if you expose raspberry in the DMZ and use a static IP or a dyndns, from everywhere you are. Let’s install!

Downloading and seeding (you do seed, right? Good people seed to at least a 2.0 ratio) is an arduous task for any regular computer, and means you’re sucking down far more electricity than you ought to be by having to leave it on overnight. What if you could offload that task to a low-powered Raspberry Pi, small enough to stuff under a floorboard and barely breaking 10W of power to do it all. That’s exactly what I’ll show you how to do today.

Here’s the plan:

  • Set up a Raspberry Pi with some USB storage, and move the system drive over to USB to extend the life of our SD card.
  • Share that over the network.
  • Configure a VPN so that all traffic is routed over the VPN, securely – and everything stops if that connection fails. We don’t want out ISP knowing which Linux distro we favour.
  • Install a remotely-manageable torrent client, Transmission.

Sounds complicated, doesn’t it? No more than a few hundred Terminal commands, I assure you. A lot of this overlaps with our Raspberry Pi NASTurn Your Raspberry Pi Into An NAS BoxTurn Your Raspberry Pi Into An NAS BoxDo you have a couple of external hard drives lying around and a Raspberry Pi? Make a cheap, low powered networked attached storage device out of them. While the end result certainly won't be as...Read More tutorial, so if you’re not so interested in the torrenting and VPN side of things, you might want to check that out instead.

USB Storage

Begin with a fresh Raspian install and connect the Ethernet interface, and plug in your USB storage (through a powered USB hub, or it’s likely you’ll face errors later as I did) – it needn’t be formatted yet. Log in remotely with the default pi /raspberry username and password combination, then run:

Change the amount of memory given over graphics to 16 megabytes – we’ll be running this completely headless, so you don’t need graphic memory. Exit, and let’s setup some partitions on the USB. We’re going to setup at least two – one to use for the system so as to preserve the life of our SD card, and the other one for downloads to be stored. Figure out first which drive is your USB.

In my case, it was easy to identify as “sda”. With that in mind, adjust the following command to enter the fdisk utility on the appropriate device.

Press p to list current partitions. To delete any existing ones, press d. Create a new primary partition, with n, then p. When it asks you for size, enter +8G. Now go ahead and create another partition for your torrent data (again, primary), or more partitions too if you wish. W will write the new partition map to the drive when you’re done.

Bittorrent

Once the new table has been written, use the following commands to format the drives as linux ext4. Use additional commands if you partitioned your drive with more than two partitions.

The last command will confirm that you’ve got the partitions mounted correctly. Next, we want to copy the SD card data to the drive – this will extend its life by avoiding constant read/write operations to caches etc. Install rsync to do this:

This will initiate a long series of file copying, so twiddle your fingers for a bit.

Adjust this to read:

Next, modify fstab to mount them on start up.

Add the following lines:

Comment out the following line which refers to the SD card:

Reboot the Pi with

Sorted! Your Pi will now mount a both a root data partition and your torrents partition

Share The Drive: Samba

Make sure we’re updated first, remove Wolfram Mathematica packages which have always caused me trouble when doing absolutely anything on the Pi (something to do with math-kernel), then install the required packages

Hit CTRL-W and type “security” to find the following line, and uncomment it.

Add the following to define our torrents shared folder:

Restart the Samba service:

Next we need to add a user to the system. Replace “jamie” with your desired username which you’ll be logging in with to access the shared folder. The following commands then ask you to create your passwords, the first at a system level and the next for Samba. Modify the last commands if you called your data drive something else (and here’s a primer on file ownership in linux).

Test – you should be able to connect from another machine on your network, and read/write files to the new share. Check they appear on the Pi too with ls from within the /mnt/torrents folder.

VPN Setup

Install the required packages

Download the OpenVPN config files from your provider. You can check out a list of the best VPNs here, but be sure to find one that’s torrent-friendly. I use privacy.io myself, but Private Internet Access is another popular option within torrent communities. Either way, you should be able to grab a ZIP file of configurations and a certificate. Put these into your torrents folder, within a directory called openvpn. Modify the following command so it points to your config file, which will almost certainly differ from privacyIO.ovpn

If you get an output like this, you’re good. Hit CTRL-C to terminate it. It’s annoying having to type the password in though, and we need a few modifications to add start and stop scripts. Edit the config file (again, replace privacyIO.ovpn with the .ovpn file your provider gave you)

Modify the following line first. Basically we’re saying we’ll store the username and password in a file called pass.txt

Save, and type:

Enter your username on the first line, and password on the next. Save, and try connecting again:

You shouldn’t be bugged to log in this time. Yay! Next, open up the config file again, and add the following lines:

This specifies some scripts we’re going to create later to perform tasks when the connection either comes up successfully, or goes down. Make sure you’re in the mnt/torrents/openvpn directory, then run the following:

Add the following which ensures traffic is sent out over the VPN:

Next, create the down.sh script

Add:

Finally, we want a script to open the connection, instead of starting it from the command line as we just did.

Paste in the VPN launch command from before. In case you’ve forgotten:

Now, make all those scripts executable, and launch the VPN script at startup.

Add the following line before the exit 0 line. We’re just telling it to start this script at startup.

Finally, reboot your system again.

Log in again, and run ifconfig. You’ll know it’s working if you see an entry for tap0 (or tun0), and are able to successful curl a webpage:

The Torrent Client

Nearly there now. Finally, we’re going to install Transmission, which is lightweight and has a nice web GUI. The following commands install, then stops the daemon – since we need to configure it first – then opens up the settings file for editing.

Change “rpc-authentication-required” to false; change “rpc-whitelist” to include your local subnet – for example:

Add or adjust the following if already present:

Next, edit the daemon startup file itself to deal with some permission problems.

Change the USER=transmission-daemon to USER=root. Reload the daemon.

Finally, we’ll install avahi-daemon to setup bonjour/zeroconf networking, which means we won’t need to use the IP address of the Pi to access it from a browser – instead we’ll be able to use the raspberrypi.local address.

Assuming your hostname is the default (raspberrypi, but can be changed using raspi-config), navigate to:

First, check your torrent IP is being correctly disguised through the VPN. Download the test torrent file from TorGuard – the download graphic looks like an advertisement, but it isn’t – and drop it in the torrents shared folder.

We’ve already configured Transmission to watch this folder for new torrents, so it should be added immediately. Go ahead and drop some legal Linux distro torrents in there as well.

The IP checking torrent should return an error, along with the IP address it detected. Make sure that isn’t your home IP – if it is, the VPN hasn’t been set up right. By default, any torrents you drop in the folder will be renamed to .added, and a .part file should be created until the transfer is finished. Verify this is the case in your shared folder.

That’s it! You now have a super low-powered, secure, torrent-downloading Pi – leaving your workstation available for better things. You might now want to look at adding a UPnP server to for streaming media around the network, or using BitTorrent Sync to create your own cloud storageBuild Your Own Cloud Storage with Raspberry Pi and BitTorrent SyncBuild Your Own Cloud Storage with Raspberry Pi and BitTorrent SyncDon't believe the hype: the Cloud is far from secure. But have no fear - now you can roll out your own private, unlimited, and secure cloud storage platform.Read More. What features will you be adding in?

Explore more about: BitTorrent, Raspberry Pi.

  1. CAN SOMEONE POST A LINK OR CAN THIS BE UPDATED PLEASE I NEED HELP SETTING UP AUTOBOOT VPN CONNECTION

  2. I only followed the VPN section on this article. The VPN starts up fine but the terminal hangs at ' Initialization Sequence Completed' and I never get my prompt back. I tried adding '&' to the end of rc.local like another another person commented example: '/mnt/torrents/openvpn/vpn.sh &'. But this did not work for me. Running Raspbian Jessie Lite

    Has anyone found a fix for this?

  3. Quick tip for people that got hung up like me. This is for Private Internet Access.
    I got to the point where you are supposed to reboot and see the tunnel interface in ifconfig but it never would work. I tried everything from creating a service with vpn.sh to adding the script to cron @reboot.

    What finally worked was adding the full path of the .pem file to the .conf file. I also stuck the .pem file and the .crt file in /etc/openvpn. In my .conf:
    .....
    crl-verify /etc/openvpn/crl.rsa.2048.pem
    ....
    Hope this helps someone!

    • Thanks, this was of great help! One more thing though...
      My vpn.sh file looks like this now:
      sudo openvpn --client --config /root/config/openvpn/Switzerland.ovpn --ca /root/config/openvpn/ca.rsa.2048.crt --crl-verify /root/config/openvpn/crl.rsa.2048.pem --script-security 2
      route-up /root/config/openvpn/route-up.sh
      down-pre
      down /root/config/openvpn/down.sh
      Are you supposed to put the route-up, down-pre and down parameters in this config file or another? Also i was not able to test a fallback, when i killed openvpn via pid transmission just switched over to the regular internet.

  4. I had tons of issues with Transmission and switched to Deluge and it worked well.
    Only question I have is how do I test the route-up,down pre,down functions of OpenVPN to make sure they work (simulate a failure to connect, and disconnect)?
    I had a few odd times it failed to connect on boot and it went on downloading with Non-VPN IP how can we ensure that doesn't happen?

    Thanks!

  5. This guide has worked perfectly till the moment you have to add a VPN server. Since privacy.io is no longer online, and PIA is a bit too expensive for me atm, how could I possibly circumvent this problem?? Any tips?

  6. When I plug in my external hard drive raspberry pi automatically recognizes and mounts it. Quick and easy. The problem comes when trying to get a windows machine to access it. The folder permissions for where it has been mounted are root so no matter what I do to grant access in samba to pi user no number of correct password entries work. I can force user = root and bam I have access but this is not what I'm looking for - ultimately I want guest read to some folders and pi user write access to all folders of the external hard drive. Any idea how to mount a drive to the pi user's folder where I'll probably have better luck or perhaps make a setting change in samba or the file permissions to allow this? I've read a ton of samba walk throughs and nobody seems to touch on this as something to look out for. I know this is slightly off topic but this article is so well written I'm hoping perhaps someone might be willing to throw a few suggestions my way if they have a few moments. Many thanks if you do.

    • I found the drive was mounted in the wrong place as well, and also found very little talk about it. My problem was solved by unmounting the drive (umount sda1) and mounting it in the correct slot, most of the instruction pages should tell you where the correct slot is, sorry it's not much information but i'll help where i can with what little i have :)

  7. this guide has an incredible amount of problems, from the samba share to the transmission permissions. you should revise it.

  8. Is it all right to skip this step?:

    Hit CTRL-W and type “security” to find the following line, and uncomment it.
    security = user

    I couldn't find it in the file. I'm on RPi3, maybe that's why? I've no idea. I'm new to Raspberry and I'm hardly familiar with Linux coding and whatnot.

    • you have to add that line after [global]

  9. Thanks for this :)

    I've followed these instructions both on my pi, and my home media server (for different locations) and its worked both on raspian (jessy) and unbuntu server :)

  10. Hi James, great post! Worked really well for me. However I am having trouble getting transmission to seed behind the PIA VPN. Seems to have something to do with the listening port, which is listed as closed. I can download just fine but seeding won't work. Any ideas on what to do? Googling doesn't give a conclusive answer, and it's complicated by all the people trying to get remote access do their Transmission through the VPN, which is not what I want to do. I just want to be able to seed.

  11. When ever I have the 'iptables -t nat -I POSTROUTING -o tun0 -j MASQUERADE' in route-up.sh I can not browse the internet or download torrents. If I remove the iptables entry it works fine.

    Does anyone know what this issue is?

  12. i'm trying this on OSMC, but even after changing the file permissions i'm getting this error: Options error: --route-up script fails with '/media/ext/torrents/openvpn/route-up.sh': Permission denied
    can anyone explain this to me?

  13. can we use a pi zero as a torrentbox

  14. So I've tried reinstalling using this guide a few times now and I keep ending up with the same problem. Transmission daemon won't start. Doesn't matter if where or when I start it but when I run 'sudo service /etc/init.d/transmission-daemon start' I get the output:

    [FAILED] Failed to start Transmission BitTottent Daemon.
    See 'systemctl status transmission-daemon.service' for details.

    Running 'systemctl status transmission-daemon.service' gives me the output:

    transmission-daemon.service - Transmission BitTorrent Daemon
    Loaded: loaded (/lib/systemd/system/transmission-daemon.service; enabled)
    Active: failed (result: exit-code) since Mon 2016-01-18 21:12:02 UT; 7in ago
    Process: 592 ExecStart=/usr/bin/transmission-daemon -f --lo-error (code=exited, status=255)
    Main PID: 592 (code=exited, status=255)

    This is no copy-paste, so there might be a few typing errors..

    Reards.

    • Me and someone in the comment section on this guide also encountered this error: http://pimylifeup.com/raspberry-pi-torrentbox/

      The author of that article updated the instructions, which fixed it for me.

  15. Hey James is there a way to get port forwarding to the pi working with a vpn setup? Seems to tell me the port is closed whatever I try.

  16. Hi! I have followed all the instructions very carefully, and I am having a couple of issues. First is that, like many commenters, I am not able to use the pi manually since starting the VPN at launch seems to prevent further input, including ^c. I can, however, ssh into the pi which is what I will be doing anyway so that is minor.

    More important is that when I add files to the torrents folder, they successfully show up in transmission's web UI but the moment they start downloading they fail with an 'error: Permission denied (/mnt/torrents/name-of-file.filetype)' I double checked '/etc/init.d/transmission-daemon' and the USER=root line is correct, as I thought that might cause the issue. Does anyone know what else might cause this to happen, and how I might correct it? I am new to linux so still learning about permissions and stuff. I assume I need to give transmission-daemon permission to modify the folder? If anyone can help, let me know!

    • And now in trying to fix this issue I seem to have somehow broken transmission watching for new torrents in the /mnt/torrents folder. Damn.

    • Add an '&' to the end of the line you added in the rc.local to call the script in background.

      /mnt/torrents/openvpn/vpn.sh&

  17. I receive the following error when trying to execute sudo fdisk /dev/sda

    fdisk: unable to open /dev/sda: No medium found

    What's the problem here? I couldn't find any solution for this particular scenario anywhere.

    • Are you sure it's /dev/sda? If you had multiple disks plugged in it could be /dev/sdb sdc etc.

      • I'm positive. I only have the SD card and the one and only external HDD. The problem persists and I have no clue what to do.

  18. Hello . Is there any chance to get to know how to make the same things on OSMC?
    I have tried to use instucions above but not all commnads are working.

  19. First of all, thanks for your tutorial. I set up my Raspberry Pi like you described. But the iptables configuration could be improved, I think. When I kill the openvpn process while downloading torrents, transmission continues but using my real ip address. Unfortunately I have never used iptables before. Do you have an idea how to configure iptables in a way that network traffic just stopps if there is no vpn interface?

    • I know both the guide and the comment I'm replying to are pretty old already but for completeness sake I thought it best to mention this: what James Bruce described in this guide is the creation of shell scripts that are executed whenever OpenVPN experiences a connection/disconnection event. This isn't a very secure method to implement a killswitch/'firewall' because the control lies solely with the application that manages the VPN tunnel.

      If you simply kill the process or if it crashes then all network traffic will continue to flow after the VPN tunnel goes down. The down.sh never has a chance to be executed in this case. Using this method means that you put all your trust into the OpenVPN client never crashing and working perfectly in general. Maybe it will, maybe it won't, but you certainly gamble with the ultimate privacy you are trying to achieve.

      The solution is to create a method that works independently of OpenVPN or any other method of connecting to an encrypted tunnel such as Libreswan (an IPsec implementation that can be used to connect via the generally more performant IKEv2 if the VPN provider supports it). The safest way of doing this is by creating a set of iptables rules that limit connections to only the IP address(es) of the VPN server. For maximum safety these rules should only be removed/changed if you desire to connect to a different VPN server. If an application supports the binding to an interface, then that should be used. Another way is to use netns to associate the VPN tunnel interface to a namespace and then launch an application by binding it to the namespace.

      One last piece of advice: If you've been searching for other methods of binding to a certain IP or interface, you shouldn't ever use LD_PRELOAD, Bindhack, liboverride et al in this situation as all these methods which dynamically link code only rebind TCP connections and not UDP which is frequently used in torrent clients. This applies to any such method that I'm familiar with, but I don't claim to know them all.

  20. hi, James Great thanks for the nice instructions. I have learned a lot from it. I just would like to know what these two following commands do. 'iptables -t nat -I POSTROUTING -o tun0 -j MASQUERADE and iptables -t nat -D POSTROUTING -o tun0 -j MASQUERADE' does it block all the internet access after vpn server is done?

  21. I have tried to follow the tutorial with a newly installed Raspbian Jessie and get as far as installing Samba. When I search smb.conf it cannot find security = user.

    If I enter all of [torrents] testparm advises that security mask, force security mode, directory security mask and force directory security mode are unknown parameters and ignored.

    When I try to restart samba I get the error message 'Failed to restart samba.service: Unit samba.service is masked.

    This is with Samba version 4.1.17-Debian.

    Do you have any idea what my problem is?

    • I noticed the same problem; I left out the 'security=user' and just rebooted the pi and samba works fine!

      • I downloaded Raspbian Wheezy and it looks like that what the instructions were written with as it worked fine.

        Andy

  22. I used a much shorter tut I found and decided to just manually activate the vpn each time

    One issue Im having though is connecting to the webUI from outside my LAN
    Even this guide seems to only get you lan and not wan access.

    Is WAN possible?
    thanks nice guide either way

  23. This is one of the better guides I've seen for this, thanks.

    A wrinkle that I'm using is binding deluge to the tunnel IP, so there's no leaks and no awkward worries about traffic going outside if the tunnel is down. But in this case, I'm deleting the default route to the tunnel, because I don't want my web browsing traffic being VPN'd. I'm doing that with a script command in the config which is kind of inelegant. I couldn't figure out the official openvpn way to do it. I wonder if you might know?

    I'm also trying to get a script running to automatically fill in the tunnel IP in the deluge config, but the examples I've found are not for raspbian and need some work.

    Love to hear your thoughts on this.

  24. Hey, I have a problem with avahi, he stop working after a short time. Can you help-me? I have a Raspberry Pi 2.

  25. Hey, im going through this and everything is working good up untill the rc.local part.

    I actually got it to automatically start the command at startup and it connects, but i am unable to do anything after. It just hangs at Initialization Sequence Completed, and I am unable to cancel it.

    I checked through and I don't think i missed anything about that, but can you help me figure out what I am doing wrong?

  26. Hi – The tutorial is fantastic from what I can see – Thanks.
    I have one issue though.
    My VPN seams to be working perfectly and I can curl/ping pages all day.
    I cannot however access the transmission webui. Any ideas anyone?
    I have tried using the local name and the ip address.
    Many thanks

    ^ Was this ever solved? I'm having the same issue. Everything works dandy, everything copied properly. I still cannot access this however...

    • I've got the exact same problem :/

      Any ideas how to resolve it?

    • Hi, Yep. I had a problem too. I added the entries into the Transmission config file after all other entries. It looks like the final entry must NOT have a trailing comma (note the final entry in the default file reads: 'utp-enabled': true
      (No comma!)

      hope that helps.

    • Sounds like you may have white listed the wrong subnet, the default is only local host (127.0.0.1) and the author added a common subnet issued by Apple Routers (10.0.1.*). If you have a different router manufacturer you may have a different subnet (usually 192.168.1.*). Alternatively the host name isn't broadcasting correctly, have you tried connecting via the direct ip?

  27. Interesting project. How about the average transfer rate for the Raspberry NAS? And would this work on the Raspberry Pi B+?

  28. Terrific explanation and instructions for a moderately complicated process. I struggled with a few odd issues (such as Samba apparently not liking my use of an underscore in the new username), but got through in the end. Shoutout to commenter 'Steve' on September 1st, 2014 who noted the very necessary --crl-verify option when using PIA proxy. Otherwise, rc.local won't setup the tun0 and gives no indication as to why.

    One question I have for the author is: Why put all the OpenVPN configs and various scripts in the /mnt/torrents folder? Since this is shared and writeable, aren't they unnecessarily exposed to tampering (intentional or not)?

    I may move that stuff to the /mnt/systemdrive, if there isn't a reason against it.

    Thanks for the article!

  29. Yeah, slow as shit though.

  30. Hi - The tutorial is fantastic from what I can see - Thanks.
    I have one issue though.

    My VPN seams to be working perfectly and I can curl/ping pages all day.

    I cannot however access the transmission webui. Any ideas anyone?

    I have tried using the local name and the ip address.

    Many thanks

    • Hi, Yep. I had a problem too. I added the entries into the Transmission config file after all other entries. It looks like the final entry must NOT have a trailing comma (note the final entry in the default file reads: 'utp-enabled': true
      (No comma!)

      hope that helps.

  31. Hi, thanks so much for the tutorial. I followed all of your instructions to the letter, but for some reason my vpn is not booting at startup. I made the edit/addition to the rc.local, but still nothing. Am I missing something?

  32. I have a question regarding access to the Pi once it is connected to the VPN. Currently everything is working on my Pi and I can SSH to it and use the Transmission WebUI while I am on my local network of 10.10.1.*, Now the issue I have been struggling to figure out is how to remotely access the Pi properly so I can use the WebUI. I have a Asus RT-AC68U as my main router and have a OpenVPN server running on it. This allows me to VPN into my house and access all my local devices. It is using tun as I need the Android support. This issue with tun is that it assigns a different IP to my clients - 10.8.0.* so when I try to SSH to the Pi or use the WebUI the VPN client on the Pi is redirecting this traffic over the Pi VPN and I never get back a response. I switched my VPN server to use TAP and DHCP of my local LAN and the issue was solved as in that configuration my client has a local LAN IP. I imagine I should be able to change the IPtables on the Pi so my 10.8.0.* traffic is not routed over the Pi VPN client but I cannot for the life of me figure it out. If anyone has any suggestions please point me in the right direction I have been reading for hours and hours with no luck.

    • I add the following lines in route-up.sh before the iptables command:

      ip rule add from x.x.x.x table 10
      ip route add default via y.y.y.y table 10

      (where x.x.x.x is the ip of my network interface wlan0 in my case)
      (where y.y.y.y is the ip of my lan gateway)

      This allows the ssh connection to be made and packets to route properly back out on the wlan0 interface through the gateway, not the tunnel.

      comment on bobhood.wordpress.com/2013/07/28/raspberry-pi-creating-a-secure-torrent-client/

  33. On second thought... I'm ssh-ed into my Pi from my mac via user@192.lo.cal.ip, could it be that, since the VPN kicks in the ssh-connection is lost because the VPN changes the ip, and on my mc it seems like the Pi is dead?

    • No, I did it all over the local network, should be fine like that. The only thing that seems odd from you've said is powering both the Pi itself and the USB hard drive from the same powered USB port - which is then also plugged BACK into the Pi as the host controller. I'm wondering if there's some weird power loop messing around with things, as that might also manifest itself like a hardware error.

      But, you could also rule out the SSH thing by hooking a keyboard and monitor up, best to try both.

    • Thanks again :-) So I did go out and got myself a Keyboard and got it all working (after a complete new install, just to make sure).

      One (similar to before) thing is still strange: when I boot everything boots well right up to 'Initialization Sequence complete'. Then I get a blinking cursor on my attached TV/monitor and nothing more. No prompt. On my attached USB keyboard I can type, sure, but to no avail. alt, command, control-C are all nicely printed on the screen, but that's it. I CAN, though, at the same time ssh in from my mac, get a prompt, everything works. I can also rdp in and get the GUI. Everything runs fine. Only on my TV/monitor the cursor keeps blinking away with so far nothing I can do about it...

      And if anyone should ask: if you use PrivateInternetAccess, download the default openvpn.zip and add --crl-verify /mnt/torrents/openvpn/crl.pem to the vpn launch command :-)

  34. Hi :-)

    Great tutorial so far, thank you very much!

    I'm stuck. I'm using PrivateInternetAccess, did everything you said. When I initiate the VPN, the Pi runs through to the point where it says 'Initializationtion Sequence Complete' - which isn't too bad - then I get a blinking cursor and that is that. A blinking Cursor. Then the Pi shuts down. The end. I repeated that circle 5 times, now I give up. For now. Maybe you have an idea?

    • Hi James, thank you for your response. I wrote a second post shortly after my first, that seemingly didn't come through.

      I'm always SSH-ed into my Pi from my Mac. No USB keyboard yet. So maybe the VPN connection screws up the SSH-connection? (I'm no expert, in case this sounds like a dumb thought...) Thought I try the same procedure with a real keyboard attached, which I'll get Friday night.

      Maybe it's PrivateInternetAccess and their configs that screws up things? Their online-chat briefly told me Pi is not supported... Tried to get a one-day-pass from privacy.io, but they're having payment problems currently. So I'll wait for that to resolve.

      And, sure, my SSD might be corrupted, though it's only a week old. Your setup is my first project with my new Pi since it's one thing that actually makes sense :-)

    • oh, and yes, Pi and external HD both are powered by the same 4-port-USB hub...

  35. when i run the vpn.sh script it shows that the route-up.sh script is not working, is anyone else experiencing this issue

    • The only thing in that script is the iptables command. Perhaps checks you're using the correct tun or tap connection?

    • Below is the log from running the vpn script. notice the error with route-up. not really sure what the problem is.. i have the exact script copied in. after running i am also unable to curl a webpage and am confused why the hardware address is all 0s
      any help is greatly appreciated

      001b]0;pi@raspberrypi: /mnt/torrents/openvpn0007001b[01;32mpi@raspberrypi001b[00m 001b[01;34m/mnt/torrents/openvpn $001b[00m Tue Aug 26 21:55:17 2014 OpenVPN 2.2.1 arm-linux-gnueabihf [SSL] [LZO2] [EPOLL] [PKCS11] [eurephia] [MH] [PF_INET6] [IPv6 payload 20110424-2 (2.2RC2)] built on Oct 12 2013
      Tue Aug 26 21:55:17 2014 WARNING: file '/mnt/torrents/pass.txt' is group or others accessible
      Tue Aug 26 21:55:17 2014 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
      Tue Aug 26 21:55:17 2014 LZO compression initialized
      Tue Aug 26 21:55:17 2014 RESOLVE: NOTE: swiss.privateinternetaccess.com resolves to 4 addresses
      Tue Aug 26 21:55:17 2014 UDPv4 link local: [undef]
      Tue Aug 26 21:55:17 2014 UDPv4 link remote: [AF_INET]xxx.xxx.xxx.xxx
      Tue Aug 26 21:55:18 2014 WARNING: this configuration may cache passwoirds in memory -- use the auth-nocache option to prevent this
      Tue Aug 26 21:55:19 2014 [Private_Internet_Access] Peer Connection Initiated with [AF_INET]xxx.xxx.xxx.xxx
      Tue Aug 26 21:55:22 2014 TUN/TAP device tun0 opened
      Tue Aug 26 21:55:22 2014 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
      Tue Aug 26 21:55:22 2014 /sbin/ifconfig tun0 xxx.xxx.xxx.xxx pointopoint xxx.xx.xxx.xxx mtu 1500
      Tue Aug 26 21:55:22 2014 WARNING: Failed running command (--route-up): could not execute external program
      Tue Aug 26 21:55:22 2014 Initialization Sequence Completed

      001b]0;pi@raspberrypi: /mnt/torrents/openvpn0007001b[01;32mpi@raspberrypi001b[00m 001b[01;34m/mnt/torrents/openvpn $001b[00m ifconfig
      eth0 Link encap:Ethernet HWaddr b8:27:eb:33:80:42
      inet addr:192.168.0.3 Bcast:192.168.0.255 Mask:255.255.255.0
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:438 errors:0 dropped:0 overruns:0 frame:0
      TX packets:439 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:43815 (42.7 KiB) TX bytes:59737 (58.3 KiB)

      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      UP LOOPBACK RUNNING MTU:65536 Metric:1
      RX packets:2 errors:0 dropped:0 overruns:0 frame:0
      TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:100 (100.0 B) TX bytes:100 (100.0 B)

      tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
      inet addr:xxx.xxx.xxx.xxx P-t-P:xxx.xxx.xxx.xxx Mask:255.255.255.255
      UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
      RX packets:4 errors:0 dropped:0 overruns:0 frame:0
      TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:100
      RX bytes:304 (304.0 B) TX bytes:780 (780.0 B)

    • I am pretty sure I did, i will try again today

    • Well evidently i didn't because i am no longer getting that error but now i am still unable to connect to anything or curl a webpage below is the output of the VPN script, i dont really see any errors so i am not sure what could be wrong

      pi@raspberrypi /mnt/torrents/openvpn $ ./vpn.sh
      Sat Aug 30 13:54:10 2014 OpenVPN 2.2.1 arm-linux-gnueabihf [SSL] [LZO2] [EPOLL] [PKCS11] [eurephia] [MH] [PF_INET6] [IPv6 payload 20110424-2 (2.2RC2)] built on Oct 12 2013
      Sat Aug 30 13:54:10 2014 WARNING: file '/mnt/torrents/openvpn/pass.txt' is group or others accessible
      Sat Aug 30 13:54:10 2014 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
      Sat Aug 30 13:54:10 2014 LZO compression initialized
      Sat Aug 30 13:54:10 2014 RESOLVE: NOTE: sweden.privateinternetaccess.com resolves to 4 addresses
      Sat Aug 30 13:54:10 2014 UDPv4 link local: [undef]
      Sat Aug 30 13:54:10 2014 UDPv4 link remote: [AF_INET]5.153.234.58:1194
      Sat Aug 30 13:54:10 2014 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
      Sat Aug 30 13:54:12 2014 [Private_Internet_Access] Peer Connection Initiated with [AF_INET]5.153.234.58:1194
      Sat Aug 30 13:54:14 2014 TUN/TAP device tun0 opened
      Sat Aug 30 13:54:14 2014 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
      Sat Aug 30 13:54:14 2014 /sbin/ifconfig tun0 10.132.1.6 pointopoint 10.132.1.5 mtu 1500
      Sat Aug 30 13:54:15 2014 Initialization Sequence Completed

    • Everything looks like it should have worked. What do you get when you do an 'ifconfig' - is there a tun or tap0 listed?

      • I have a very similiar ifconfig output. It lists tun0 but still doesn't work.
        It looks like this.

        tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
        inet addr:10.8.8.90 P-t-P:10.8.8.89 Mask:255.255.255.255
        UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
        TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:100
        RX bytes:0 (0.0 B) TX bytes:304 (304.0 B)

        My vpn.sh script output seem OK. I did everything as said in the tutorial, except I moved my openvpn directory from /mnt/torrents/ to /etc/. However I did update all scripts and configs with the right location. My VPN (NordVpn) works fine on my Windows PC though.
        I realise this article is pretty old but I hope to find some help here. Thanks.

  36. Hi James,

    thanks for the guide, it helped me a lot. Unfortunately I have a little problem. ifconfig shows that there is neither a tap0 nor a tun0. Curling a webpage results in: Couldn't resolve host xyz. Do you have any idea how to fix this?

    • Thanks for your reply. The vpn wasn't working due to a DNS problem, which I fixed. Now the Pi is working as intended. Thanks for the guide.

  37. I know this is an old article, but do you know of a way to also port forward the Raspberry Pi using Private Internet Access?

  38. James, I have yet to locate an error for the /etc/rc.local issue. It just seems like it isn't be called at all. I'll keep digging.

  39. Thanks for the guide! I am experiencing an issue. It doesn't seem like any of my changes are surviving a reboot. The VPN doesn't auto connect and the mounts don't seem to be correct. The VPN connects fine if I launch the script. My rc.local edits survive a reboot as well as changes to fstab. Also, a mount -a seems to mount fstab entries that exist but aren't mounting at system start.

    Any ideas what I might be experiencing? Thanks.

    • Hi Mat. The mounts might be incorrect because after the initial SD card boot, everythign is handed over to USB, and the fstab is different at that point - if you see what I mean?

      As for the VPN - can you verify you have a VPN.sh, which is exectuable by all, and does work to connect the VPN? And it's been added to /etc/rc.local? Have you checked the sysem log for errors?

    • fstab should always end up with blank line.

Raspberry Pi Torrent

Why Set Up A Dedicated Torrent Server?

Quick Links

  • Install The Client
  • Configure Your Storage

You can download torrents on just about any computer fairly easily, so why would you want to set up a dedicated torrent server anyway? Well, there are a couple of good reasons that make the extra setup worthwhile.

First, you can access it from anywhere on your network. That means, if you want to download something, you don’t necessarily need to be on the same computer. You can use a laptop or computer in an entirely different room. You can also easily access and manage your torrents from anywhere. You can check if something’s done downloading from outside your house or change the priority of your downloads on the fly.

Having a dedicated server also means that you can turn off your computers without worrying about stopping your download progress. Your server will always be running in the background, even when your computers are off or you’re not even home.

A server is also much easier to manage. You don’t have to worry about any of the other programs on your computer getting in the way, or worse, crashing. The server also limits the amount of VPN connections you need to worry about, depending on your network situation.

What You’ll Need

Surprisingly enough, you don’t need much here. Everything will be based on your Raspberry Pi.

  • Raspberry Pi 3 or better
  • External hard drive or a networked drive
  • Ethernet cable
  • Power cord for Pi
  • MicroSD card 16GB+

Flashing The SD Card

Raspbian is the default operating system for the Raspberry Pi. It’s also the perfect option for setting up the Pi as torrent server. Go over to the Raspberry Pi Foundation’s download page, and get the latest release of Raspbian Lite. You’re not going to need a desktop environment on your server. The lighter it is the better.

Once you have your image, unzip it. You want a file with the raw .img extension. Then, insert your MicroSD card into your computer.

If you don’t already have a preferred tool for flashing images to SD cards, there’s a great cross-platform application, Etcher, that you can use on any operating system to easily flash your image. Download the correct version for your OS.

Once you have Etcher, open it up or install it. The program breaks the process down into three simple steps. In the first section, select your image file. Then, find your SD card. When everything looks correct, click the button to flash your image. The process will take a while, so be patient.

After Etcher is finished writing your image, there’s one more thing you need to do. Mount your MicroSD on your computer. Look for the “boot” partition. Create a blank file in the base of the “boot” partition, called “ssh.” That file tells the Pi to enable SSH access by default.

Install Raspbian

Unmount your SD card, and remove it from your computer. Plug it in to the Pi. Connect the Pi directly to your router with an Ethernet cable. When everything is set, plug it in.

The Raspberry Pi will take some time to resize its partitions and fill up the SD card. While it does that, open your web browser and navigate to your router’s web interface. Keep an eye on the listing of connected devices. Eventually, the Pi will pop up as “raspberry.”

Once you see the Pi on your network, you can use SSH to connect to it. Open up OpenSSH, and connect with to the Pi’s IP address. The username is Pi, and the password is “raspberry.”

Set Up A User

You’re probably going to want to create a new user for Deluge. That user will run Deluge as a service daemon, and not much else.

Make that directory and grand ownership to your Deluge user.

Connect To A VPN

It’s not strictly necessary to connect to a VPN, but it’s a very good idea. This process won’t be exactly the same, depending on your VPN provider, but it should be similar enough. Start by installing OpenVPN on Raspbian.

Next, download the OpenVPN configuration files for your VPN. Again, this part is going to be different, depending on who you’re using. Most VPN providers will provide OpenVPN configuration files either by saying just that or as their Linux option. They usually come in a big .zip file. The files themselves usually have the .ovpn extension.

Find a location that you want to use. Depending on your needs, it might be a good idea to pick a server located outside the US. Copy that file into the system’s OpenVPN folder, and rename it.

$ sudo cp Downloads/config.ovpn /etc/openvpn/client.conf

Once it’s there, create a file for authentication. Use a plain text file, called auth.txt. On the first line, place the username for your VPN account. On the second line, add your password. Open the VPN configuration that you just copied over. Find the line below and make yours match the example.

That will automatically log you in. Next, add the block below just before your certificates. These will handle logging and starting and stopping the service.

Save your file and exit. Then, restart the service.

Create A VPN Killswitch

If you’re using torrents behind a VPN, your probably want a reliable killswitch that will cut off your connection of you lose contact with the VPN. Thankfully, that’s something that’s very easy to do on Linux systems with a firewall. Start by downloading UFW to make firewall management much easier.

Once you have UFW, you can start setting up your rules. Start by disabling UFW.

Now, tell UFW to block everything by default.

Allow all connections from the computer itself and the local network.

Then, allow everything through the VPN. Check the actual interface of your VPN.

Finally, allow contact to your VPN’s DNS server. Again, check the actual IP in /etc/resolv.conf.

When that’s all ready, re-enable UFW.

Install Deluge

You’re finally ready to install deluge on your server. So, do just that.

Wait for the install to finish. It should be pretty quick.

Set Up The Deluge Server

In order to allow connections to your server from other computers, you need to enable remote connections. Change to your Deluge user, and open up the Deluge console.

Then, enable remote connections.

Now, stop the Deluge daemon. You can do that by looking up the process and killing it.

You need to add login records for your users. The file is located at / var/lib/deluge/.config/deluge/auth. Add your user records in the following pattern.

The number denotes privileges. 10 makes the user an admin user. When you’re done, save an exit.

Create A Deluge Service

Since you want Deluge to start up automatically with the Raspberry Pi, you’re going to need to write a simple systemd service. Don’t worry, this is actually provided in the Deluge documentation. Create a file at /etc/systemd/system/deluged.service. In it, put the following:

Test it out by starting up the service and checking the status.

If the service is up and running, make the change permanent by enabling the service.

Install The Client

Raspberry Pi Torrent Box

You can now install the Deluge client to connect to your server. Deluge is open source and readily available across multiple platforms.

Windows

Go to the Deluge download page, and grab the latest release for Windows. Run the .exe. The installation process is fairly standard. Feel free to click through the wizard, and accept the defaults.

Auto Download Torrent Rapberry Pi 3

Linux

As you’ve probably guessed, the Linux process is very easy. Just install the client with your package manager.

Raspberry Pi Games Download

Connect To Your Server

Open the Deluge preferences by clicking “Edit”?”Preferences.” On the side of the window that will open, you can find the “Interface” tab. Click on it. Near the top of the window is a checkbox that controls Deluge’s classic mode. Uncheck the box to disable it.

Click on the “Edit” button again. This time, select “Connection Manager.” By default, you’ll see the localhost IP there. Below the listing, there are buttons that allow you to add and remove connections. Click the “Add” button. Enter your server’s IP in the “Hostname” field. Leave the port number the same. Then fill in the username and password that you set up. Click “Add” to finish.

Back on the main “Add” window, you can now highlight your new entry and click on the “Connect” button at the bottom to connect to the server.

Configure Your Storage

Before you start downloading anything, you’re going to need to configure your storage. The two main options here are an external USB hard drive or a networked drive. Either way works. You just need something much larger than what the Raspberry Pi supports.

USB

Plug your USB drive in to the Pi. Then, through your SSH console, look at the devices available.

You should only see the USB drive and possibly your SD card. The SD card will have multiple partitions, while the USB drive will probably only have one. It’ll look something like this:

In this case, the external drive is sdb, and the partition is sdb1. Create a directory to mount it to.

Now, open /etc/fstab with your text editor and create an entry to mount the drive automatically on boot.

Make sure that the path and the filesystem type match your drive. If you’ve only ever used the drive with Windows, the format is probably NTFS, and you need to install ntfs-3g on the server.

Run the following to mount the drive.

Networked

All networked drive configurations are different, but if you’re using a Linux NFS drive, you can create a directory to mount to and add a record to /etc/fstab.

Then, open fstab, and add your drive.

Save and exit. Then, mount your drive.

Configure Deluge

Back in the Deluge client, you can set the download directory for your torrents. Click on “Edit”?”Preferences.” In the first “Downloads” tab, you can set the download location for your files. Choose the location of your newly mounted drive.

Download A Torrent

To download a torrent with Deluge, click on the plus sign icon at the top left of the window. A new window will open with different options for you to add the torrent. The two most common ones are going to be a torrent file and a URL. For the file, you can click on the button to browse to the location of your torrent file. Click the URL button, and paste in a URL to add a torrent via URL. The URL function works for magnet links.

The newly added torrent will appear in the main body of Deluge’s window. From there, you can track the progress of the torrent. If you would like to change the priority of your torrents, you can right click on them, and use the “Queue” option to move them up and down.

Right clicking on a torrent gives you a host of other options too. You can set download and upload limits, and pause a torrent outright too. There is also an option to remove a torrent too. Once you’re finished downloading, you can remove the torrent without removing the downloaded file. That will stop you from seeding. Of course, you can leave torrents seeding, and control the network usage of those completed torrents too.

Closing Thoughts

You now have a fully functional torrent server that’s configured and ready to download or seed as many torrents as you need. The server will run continually, independent of your computers. You’re also set up to run through a VPN, for added privacy and security. Enjoy your new torrenting experience!