Configuring Raspberry Pi as a File and Bit Torrent Server

by Michael Burton

This project will configure a 512MB Raspberry Pi as a file server and bit torrent server. This is mostly based on an article in the February 2013 issue of Linux Format magazine.

Hook up the hardware and power it on. If you have already worked with Raspbian, the card should be configured. If it isn't, google "configuring raspberry pi" and follow the steps.

To discover the RPi IP address, go to your LAN router's web page and look at LAN status. One of the IP addresses should be for the RPi. On my D-Link router, that information is in the Status section and it looks like this:

Alternatively, if you have a keyboard and monitor hooked up to the RPi, you can just enter 'ifconfig' and get the IP address from that output.

From a terminal on one of your LAN computers, ssh in to the RPi with that IP address:

pi@raspberrypi ~ $ ssh pi@

When asked, enter the pi user's password (the default is raspberry)

Setting Up The Raspberry Pi

Since the RPi will be running headless, there is no real need to allocate a lot of its memory for the display. To change your RPi configuration, enter

pi@raspberrypi ~ $ sudo raspi-config

Select the memory split option and change it to 16 (16 is the minimal amount you can allocate for display memory). Hit Enter.

Select Update and hit Enter. After it finishes, select Finish in the raspi-config screen. You may be disconnected if any updates were done.

Reconnect your LAN computer to the RPi if necessary. Now add a new user (and password) to the RPi with

pi@raspberrypi ~ $ sudo adduser mburton

In place of 'mburton', you can add any username you wish. Now add the new user to the RPi's users group

pi@raspberrypi ~ $ sudo usermod -a -G users mburton

The RPi can now be accessed using that user, which will come in handy when you actually use the RPi file or bit torrent server. You can add as many users as you wish using the above 2 commands.

Setting Up the RPi File Server (Samba)

To install the samba file server on the RPi, enter

pi@raspberrypi ~ $ sudo apt-get install samba samba-common-bin

When the apt-get command is completed, you will have a Samba server installed and running on the RPi. Now add some users to the samba configuration. You can add as many users as you wish.

pi@raspberrypi ~ $ sudo smbpasswd -a pi
pi@raspberrypi ~ $ sudo smbpasswd -a mburton

We will now make some changes to the Samba configuration. First, you should back up the Samba configuration file with

pi@raspberrypi ~ $ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.original

You can now edit the smb.conf configuration file.

pi@raspberrypi ~ $ sudo pico /etc/samba/smb.conf

In the editor, remove the '#' from in front of the line that says 'security = user'. Then use the editor Search function (the F6 key) to find [homes]. Change the line

browseable = no


browseable = yes

then change the line

read only = yes


read only = no

Press Ctrl-O then Enter to save the file. Press Ctrl-X to exit from the pico editor.

You must now restart the Samba server so it will pick up the new changes.

pi@raspberrypi ~ $ sudo service samba restart

There are a couple more changes we need to make to Samba, but first we must get the hard drive connected.

Setting Up the Hard Drive

If the external USB drive hooked up to the RPi is not running, turn it on.

Once it is powered up, type the following to verify that the drive can be seen and to pick up some important drive information.

pi@raspberrypi ~ $ sudo fdisk -l

You should see information about all the file systems hooked up to the RPi, including the external drive. You should see something that looks like this

	Disk /dev/mmcblk0: 7948 MB, 7948206080 bytes
	4 heads, 16 sectors/track, 242560 cylinders, total 15523840 sectors
	Units = sectors of 1 * 512 = 512 bytes
	Sector size (logical/physical): 512 bytes / 512 bytes
	I/O size (minimum/optimal): 512 bytes / 512 bytes
	Disk identifier: 0x000f06a6

	        Device Boot      Start         End      Blocks   Id  System
	/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
	/dev/mmcblk0p2          122880    15523839     7700480   83  Linux

	Disk /dev/sda: 250.1 GB, 250059350016 bytes
	81 heads, 63 sectors/track, 95707 cylinders, total 488397168 sectors
	Units = sectors of 1 * 512 = 512 bytes
	Sector size (logical/physical): 512 bytes / 512 bytes
	I/O size (minimum/optimal): 512 bytes / 512 bytes	
	Disk identifier: 0x0003b0a4

	   Device Boot      Start         End      Blocks   Id  System
	/dev/sda1            2048   488397167   244197560   83  Linux

The last entry (the one connected to /dev/sda1) is the external hard drive we will use for file storage. Note that it uses a Linux file system (ext4). It could just as well be fat32 or ntfs.

Now make a directory on the RPi to mount the hard drive to, then mount the drive.

pi@raspberrypi ~ $ sudo mkdir /mnt/usb
pi@raspberrypi ~ $ sudo mount /dev/sda1 /mnt/usb

The hard drive is now mounted, but only until the next time the RPi is rebooted. We need to add an entry to the file system table (fstab) so the drive will always mount when the RPi is turned on. To do that, we need to know the unique id of the hard drive. You can discover this with

pi@raspberrypi ~ $ sudo blkid

You will see something like this:

	/dev/mmcblk0p1: SEC_TYPE="msdos" UUID="8B12-9112" TYPE="vfat" 
	/dev/mmcblk0p2: UUID="29b6c2f5-5469-49f2-abd5-daa9149021cc" TYPE="ext4" 
	/dev/sda1: LABEL="ext4usb" UUID="c6ea19ea-2a8b-4dc6-a38e-2d5dfda38ad1" TYPE="ext4"

The two pieces we need are the UUID and the TYPE (file system type) for /dev/sda1. Note that this particular hard drive has a type of ext4. Now we need to add an entry to the fstab.

pi@raspberrypi ~ $ sudo pico /etc/fstab

In the editor, go to the bottom of the file and enter the information you got from the blkid command

UUID=c6ea19ea-2a8b-4dc6-a38e-2d5dfda38ad1 /mnt/usb ext4 defaults 0 0

UUID is from blkid, /mnt/usb is our mount directory, ext4 is the file system type. The rest of the line has to do with drive access.

Save the file and exit. Then reboot the RPi.

pi@raspberrypi ~ $ sudo reboot

You will lose the connection to the RPi in the terminal. Wait a minute or two and then reconnect using ssh.

Use the ls command to verify that the hard drive is connected.

pi@raspberrypi ~ $ ls -l /mnt/usb

total 8
drwxr-xr-x 2 root root 4096 Jan 29 07:52 Documents
drwxr-xr-x 2 root root 4096 Jan 29 07:52 Downloads

Note that this hard drive has a couple of directories on it already. We will allow access to those directories with Samba. If you don't have any directories on your hard drive, you should make some with sudo mkdir /mnt/usb/directoryname.

Now let's modify the Samba configuration again to allow user access to those directories.

pi@raspberrypi ~ $ sudo pico /etc/samba/smb.conf

Go to the end of the file and enter the following

comment = Place your downloads here
path = /mnt/usb/Downloads
browseable = yes
writable = yes
read only = no
valid users = @users

comment = Important documents go here
path = /mnt/usb/Documents
browseable = yes
writable = yes
read only = no
valid users = @users

You can restrict the user access to the Documents directory if you wish. If I wanted to restrict access to only the pi and mburton user, I would use

valid users = pi, mburton

We now have a completely configured Samba file server running on the RPi.

Setting Up the RPi Bit Torrent Server (Transmission)

Our next step is to download and install the Transmission bit torrent server. Enter the following

pi@raspberrypi ~ $ sudo apt-get install transmission-daemon

At the completion of this apt-get command, we have the transmission server installed and running. Now we need to create a transmission directory on our hard disk and change its ownership.

pi@raspberrypi ~ $ sudo mkdir /mnt/usb/public
pi@raspberrypi ~ $ sudo chown debian-transmission /mnt/usb/public

Now we can add that directory to the Samba configuration.

pi@raspberrypi ~ $ sudo pico /etc/samba/smb.conf

Go to the bottom of the file and add

comment = Public share for bit torrents
path = /mnt/usb/public
browseable = yes
public = yes
writable = yes
guest ok = yes

Save the file, then restart the Samba service

pi@raspberrypi ~ $ sudo service samba restart

We will now configure the transmission server. First, we will stop the server and then add that daemon to our users group.

pi@raspberrypi ~ $ sudo service transmission-daemon stop
pi@raspberrypi ~ $ sudo usermod -a -G users debian-transmission

Now we can modify the Transmission configuration file.

pi@raspberrypi ~ $ sudo pico /etc/transmission-daemon/settings.json

Find the rpc-whitelist-enabled entry and change it to allow users to connect from all computers.

"rpc-whitelist-enabled": false,

Go up to the download-dir entry and change it to

"download-dir": "/mnt/usb/public/downloads/Complete",

Next, go to the incomplete-dir-enabled and change it to

"incomplete-dir-enabled": true,

Now change the incomplete-dir to

"incomplete-dir": "/mnt/usb/public/downloads/Incomplete",

The final configuration change to Transmission is to set up the user authentication so not everyone can queue torrents for downloads to the RPi. Find the rpc-authentication-required entry and change it to

"rpc-authentication-required": true,

Don't worry if this is already set to true. Now enter a new password for authentication. Transmission will automatically encrypt this when you restart the daemon.

"rpc-password": "raspberry",

You are done with the Transmission changes, so save the file and exit from the editor. Finally, start up the daemon

pi@raspberrypi ~ $ sudo service transmission-daemon start

At this point, both the file server and the bit torrent server are properly configured and are working.

Using the Bit Torrent Server

The Transmission server has a web interface. To access it, connect to your RPi using your browser and the RPi's IP address and the standard Transmission port number, which is 9091.

An authentication dialog will be presented. The user name is always 'transmission'. the password is the one we just inserted into the Transmission configuration (in our case, it is 'raspberry').

When the authentication is accepted, the Transmission web page will be presented.

To add a new torrent download to the server, click on the folder icon, then supply the address of the torrent file. Transmission will take care of everything else.

When a torrent download is completed it will be moved from RPi's public/downloads/Incomplete directory to its public/downloads/Complete directory. You can copy the file to your computer using the file server web interface.

Using the File Server

You can access the file server on the RPi from your other LAN computers using your web browser. Bring up the browser and enter 'smb://' followed by the IP address of the RPi. You will see something like the following.

You can browse through the accessible RPi directories. If you see a file you want to transfer to your computer, right-click on the file, then click on Save Link As to save it to your computer.