Previously, we installed Ubuntu and setup SSH on a computer that we are going to be using as a home server. Now it’s time to configure some things and install more software to make this home server do stuff.

Basics of Ubuntu Command Line

There are a few different commands that are used to navigate through the file system. The ls command lists all of the files and folders under the current directory (type ls -a if you want to show hidden files). The cd command is used for navigating into directories. You have to type cd and then the directory path. Paths that begin with a backslash, like /home/jake, are absolute paths. The first / is the root of the file system. Paths without a backslash are relative. If you type cd Downloads, it will navigate into the Downloads folder if it exists under the current directory. You can type cd .. to navigate into the parent directory.

Here’s is an example putting all of this together.

Navigating

  • Note: The ~ is the user’s home directory path. It is a shortened version.
  • When nothing is displayed after ls is entered it means the directory is empty.

Managing Users

Adding and deleting users is something that may come in handy. To add a user just type sudo adduser username replacing username with whatever you want. The sudo at the beginning of this command allows you to execute commands with root permission without being logged in as root. The user, root, is the superuser and has complete control over the computer; one wrong command could destroy the whole system. It is best practice to use sudo instead of logging in as root for commands that need this level of permission. If you want to give the newly created user sudo access, you must add them to the sudo group. Use sudo adduser username sudo to do this. Then next time the user logs in they will have sudo access.

To delete a user type sudo deluser username. I suggest not deleting users you didn’t create. You don’t know what you could be messing up. Only delete users you created that you don’t want anymore.

To change a password for a user type sudo passwd username.

Package Manager

You’ll want to keep the software on your system up to date. To use Ubuntu’s package manager to update software you need to run two commands. First run sudo apt-get update, which will update the package index from all of the software repositories. Then run sudo apt-get upgrade, which will actually upgrade all of the software that’s available. Make sure you do this every once and awhile.

To install new software use the command sudo apt-get install name, replacing name with the name of the package. To remove use sudo apt-get remove name. Or use sudo apt-get purge name, which will also remove all configuration files.

Shutdown and Reboot

To shut down the server use the command sudo poweroff. To reboot it use sudo reboot. Ubuntu, and Linux in general, is very stable so you will not have to reboot very often, usually only when there is a problem. I’ve had my server running for months without rebooting. Some systems even run for multiple years continuously.

Monitor System Processes

Using htop, a software package, you can monitor system performance. Install htop using sudo apt-get install htop. To use it type htop. You can see CPU usage, RAM usage, and all of the running processes.

htop

Webmin

Managing a server completely using the command line and editing configuration files can be difficult, especially for a beginner. Webmin aims to make it easier. It is software that allows you to manage some aspects of your server through a web interface.

To install it we need to add another repository. Use sudo nano /etc/apt/sources.list to edit the sources.list file and add this line to the very bottom: deb http://download.webmin.com/download/repository sarge contrib. Any line beginning with # will be ignored so you can write notes to your self above or below this. Use CTRL-X to close the file; when asked to save, type y and ENTER.

Now, we also need to fetch and install the GPG key for the repository. Type cd to navigate into your home directory, then use wget http://www.webmin.com/jcameron-key.asc to download the key. Use sudo apt-key add jcameron-key.asc to add the key. After you are done, run sudo apt-get update. When you’re done with all of this, delete the key file with rm jcameron-key.asc (make sure you’re in your home directory).

Now install Webmin with sudo apt-get install webmin. Let’s reboot the system for the first time just to be safe (sudo reboot).

With Webmin installed you should now be able to log into the web interface. In a web browser, type in your server’s IP then :10000. That is the port number for the web interface. Your address bar should look something like this, 192.168.1.2:10000. Press enter, then type in your username and password that you have been using.

Webmin login

Take awhile to look around the interface and see all of the different tools. Just be sure not to change anything, especially if you don’t know what it does.

Webmin interface

Mount Disks

If you have an external USB drive it needs to be mounted in order for the drive to be accessible from the server. First, make sure you have the hard drive set up with partitions and a working file system. I suggest doing this on your desktop computer, it’s hard to do this from command line. Then, plug in the hard drive you are using. To see a list of all the hard drive partitions plugged into the system use sudo fdisk -l. You need to mount each individual partition that you want to use.

The device path should be something similar to /dev/sdb1. We need an empty directory to mount the partition. Make a new directory under the /media directory using sudo mkdir /media/name (replace name with whatever you want).

Now let’s mount a partition. Use sudo mount -t ntfs /dev/sda2 /media/name -o uid=1000,gid=1000,utf8,dmask=002,fmask=002 to do this. Replace ntfs with the type of file system you are mounting. Replace /dev/sda2 with the device path. Finally, /media/name is the directory to mount to (use the one we just made).

If this worked successfully you should be able to navigate into the directory it’s mounted to and view any files that are on it.

Every time the server is rebooted the partitions will no longer be mounted. It is kind of a pain to enter the above command every time we reboot. Luckily, you can configure the system to automatically mount partitions during startup in the /etc/fstab file.

Open the file to edit it: sudo nano /etc/fstab. The file should already have contents. At the bottom, add /dev/sda2 /media/name ntfs uid=1000,gid=1000,utf8,dmask=002,fmask=002 0 2. Replace all of things that were described above. Also, make sure you replace uid and gid with the user and group id for the main user you are using. They are both normally 1000, unless you created a different user and are using that. You can see a list of all users and groups in Webmin. It’s under the System section. The dmask and fmask properties set the permissions for directories and files that are mounted. In the provided line, the permissions are set so the user and group specified have read, write, and execute permission while everyone else only has read and execute permission. Permissions in Linux are very important; they are meant to protect files from other unauthorized users and/or programs.

Once you have added a line for each external partition you want to mount, save and then reboot. Now, every time the system starts it should automatically mount the partitions. You don’t need to run a command every time.

If something isn’t working right, make sure you have the right device and file system specified in the fstab file. You should be able to navigate through the drives if everything is working. Also, make sure the permissions are correct in the fstab file. Your main user should have full access to all of the files.

File Sharing

One of the main uses of a home server is having a central place to store files that other computers on the local network can access. To set this up we will use software called Samba. Samba implements the SMB protocol which Windows, Linux, and Mac support. You will be able to access your files from any OS.

To install Samba run sudo apt-get install samba. It may already be installed.

Almost all Samba configuration can be done through Webmin. On Webmin, search for Samba and click on the Samba Windows File Sharing module. You can make any directory on your server into a file share, including ones from external drives. To make a file share click on Create a new file share. Choose the directory you want, pick a share name, and select your user and group instead of root. Also, change the permissions box to 775. Finally, click create.

Then, click on the share and go to Security and Access Control. Make sure it is writable and guest access is enabled. You should leave the guest user as nobody. Remember to save your changes. Then go to File Permissions for the share and change the new file mode and new directory mode to 775 instead of 755. You need to do all this for every share you create.

Restart Samba to put these changes into effect (there is a button on Webmin). You should be able to access all of the file shares you made from another computer on the same local network. However, you should not be able to login or gain write access, only anonymous login. To setup write access we need to create a Samba user for our Linux user. Use the command sudo smbpasswd -a username to do this. It will ask for a password and then create a Samba user for you. Restart the Samba server and you should be able to log into the Samba share from another computer with the user you just made and have full access to the files. Guest access should only allow read access.

Make sure the directory you are sharing has correct file permissions. You should have complete read and write access to files from mounted external drives and everything in your home folder. If you want to use internal storage to make a new directory to share I suggest keeping it in your home folder to stay organized.

Transmission (BitTorrent)

Transmission is a BitTorrent client that we will use for torrenting on the home server. It is free and open-source and can be run without a GUI. It has a built in web interface which is the easiest way to control it and download torrents.

Install Transmission with sudo apt-get install transmission-cli transmission-common transmission-daemon.

You need to edit the configuration file to setup a few things. First shutdown Transmission: sudo service transmission-daemon stop. Then edit the file: sudo nano /var/lib/transmission-daemon/info/settings.json. You should add something like 192.168.*.* to the whitelist to allow remote access on your local network. The line should look like this, "rpc-whitelist": "127.0.0.1,192.168.*.*", . Change rpc-password to whatever you would like, this is the password for the web interface. It should be something like "rpc-password": "password", . After Transmission starts this will be rewritten into a hash. The default username is transmission. Next, start Transmission back up with sudo service transmission-daemon start. If you are getting an error, most likely something is wrong with the configuration file.

In a web browser go to 192.168.1.2:9091, replace the IP with your server’s. It will ask you for your username and password and then should display the web interface.

Transmission Web Interface

Now let’s setup directories for where torrents will be stored. Make a folder called transmission wherever you want to store torrents: mkdir transmission. In this folder (cd transmission), make two more folders: mkdir incomplete complete. Now we have to configure Transmission to store incomplete torrents and complete torrents in these directories. First shutdown Transmission: sudo service transmission-daemon stop. Open the configuration file: sudo nano /var/lib/transmission-daemon/info/settings.json. Change dowload-dir and incomplete-dir to the folders you just made. Also make sure incomplete-dir-enabled is set to true.

One more thing we should do is add the debian-transmission user to the main user’s group so Transmission will have permission to access the folders we just made. Use sudo usermod -a -G jake debian-transmission to do this. Replace jake with your user’s group. You can look at all of the users and groups through Webmin. Now start Transmission back up and everything should be ready to go.

Try adding a torrent and watch it download to make sure everything works. To access and use anything you download, you either have to make the complete directory a Samba share or move the torrents to a Samba share once they are done. Files are not much use just sitting on a server.

If you want to setup your server to automatically download torrents I suggest looking into Sick Beard and CoachPotato, two Python-based software packages. I won’t cover that here.

Conclusion

With everything I have covered, you should have a basic home server that functions as a file share and a torrenting box. Now you have a central place to store all of your files and no longer have to keep your desktop running for torrents.

I use my server in conjunction with a media center which streams from the server. For this I use a Raspberry Pi running Kodi.

I hope you found this guide useful and learned something. Leave a comment if you have any feedback or if something isn’t working.