One very handy use for your home server is in using it as a file server. If you have more than one computer at home, you know what its like to want to work on a file or document, for instance, which is sitting on your other computer. Having a home file server allows you to save files to your always on server and make them available to all of your machines on the network. This is also useful for saving photos, music or movies centrally. Later on we will be setting the server up to show your photos, music and movies, so being able to move these files to the server conveniently makes it all the easier to work with these later applications.
In a Unix/Linux world, the preferred way to share files is through using the NFS (Network File Sharing) protocol. Windows however uses SMB (Server Message Block) for file sharing across a network. Samba is an open source implementation of the SMB protocol, which allows you to do file and print sharing from a linux server to Windows clients, i.e. Windows laptops/computers on the network. As such, it is a hugely popular file sharing protocol and so Mac and other devices are able to connect to and use it also.
Samba is included in the Ubuntu software repositories, so to install it, run:
sudo apt-get update sudo apt-get install samba
Next, decide what directory you are going to use for sharing files from. If the directory doesn’t exist already, create it and set the permissions to give everyone access to it:
sudo mkdir /srv/samba sudo chmod 777 /srv/samba
The Samba configuration files are saved at /etc/samba/smb.conf. There is a lot of detail in this file, so while it is worthwhile reading through it, I would recommend renaming it to save it as a backup copy, and then creating a new smb.conf file, to which you can add only the lines needed for your file server
cd /etc/samba sudo mv smb.conf smb.conf.BACKUP sudo nano smb.conf
Add the following configuration lines into the smb.conf file:
[global] workgroup = WORKGROUP server string = File Server security = user map to guest = Bad User [files] path = /srv/samba read only = no guest ok = yes browseable = yes
The final step is to add your user to the Samba user account.
You will be prompted to enter a password. Leave this blank (just press Enter). Once done, restart the samba server and you should be ready to go
sudo service smbd restart
To connect to your file server, open File Explorer and go to My Computer. Click Map Network Drive, and enter the IP address of your server and the share name you gave.
Movies, Music, etc.
Often you may want to set up separate shares for different media types, such as movies, music, etc. To do this, create the additional directories, set the permissions and then edit smb.conf to include these shares. For example:
sudo mkdir /srv/movies sudo chmod 777 /srv/movies sudo nano /etc/samba/smb.conf
and add the following to the bottom of the file:
[movies] path = /srv/movies read only = no guest ok = yes browseable = yes
Once you restart samba the new share should be available for use
Samba Recycle Bin
With Windows computers, we are used to files going to the Recycle Bin when they are deleted, that is, we have a last chance to rescue something in case we didn’t mean to delete it. In the Linux world, once you delete something, it is gone. This is very important to bear in mind when working from the command line and using the rm command. This is also the case when you set up a Samba file server; by default, deleting a file deletes it permanently. You do have the option though of adding a recycle bin, to have a safety net for any items accidentally deleted.
To enable the Recycle Bin for a file share, add the following lines to smb.conf under the share, and restart Samba. You will need to create the folder (mkdir /srv/samba/recycle_bin) beforehand. Any file types added to the recycle:exclude parameter will not go to the recycle bin when deleted, and be permanently deleted rather. You will need to monitor the recycle_bin directory periodically to clear it out, in order to reclaim space.
[files] vfs object = recycle recycle:repository = /srv/samba/RecycleBin recycle:keeptree = yes recycle:versions = yes recycle:exclude = *.tmp,*.temp recycle:exclude_dir = RecycleBin
Samba uses port 445, so if you are running a firewall on your server (as you should be!), be sure to enable access to this port.