Home Server Part 5 – Setting Up Samba
At this point, you’re ready to start hosting your own services, but to make your life significantly easier I have an optional – though highly recommended – step. If you ever want to share files back and forth between your Linux server and another computer on your network, the most straightforward way to do it is with Samba. In this tutorial, I’ll walk you through the process.
If you haven’t used Linux before, one of the strange new discoveries you’ll make as you go along is that new programs can be installed without going out to a website and downloading a file and clicking on it. Rather, a significant amount of software can be installed automatically by typing in a command in the console. Ubuntu Server, which we installed in the previous tutorial, like most Linux distributions, has a built-in package manager to perform this step. All of this to say that you can install Samba on your server in a about thirty seconds as long as you have an internet connection.
First, you should update your package index to the latest available, using this command:
$ sudo apt update
Along with installing Samba, I want to give you a little explanation of what you’re actually doing, so lets take a look at this command. The $ means you’re performing this in the shell. sudo stands for superuser do. In Windows terms, you’re performing the command afterwards as an administrator with full access to the computer. apt is the Advanced Packaging Tool and update is the command you’re giving it. So, in full, you’re telling the Advanced Packaging Tool (your package manager) to update it’s indexes with full administrative privileges.
Because you’re using the superuser, you’ll need to type your password. One thing that can instantly confuse new Linux users is that when you type your password, you’ll have no indication that any characters are being added, but they are. This is a safety feature built into the operating system.
Next, you want to tell apt to install samba. When prompted if you want to install after being told the file size, just type ‘Y’ and enter to continue:
$ sudo apt install samba
Finally, you want to make sure you’re server is running. This should happen automatically but it never hurts to check. systemctl is a service management tool, status is the command you’re giving it, and smdb is the Samba service name you’re checking:
$ sudo systemctl status smdb
You should see something like this:
And that’s it! Samba is installed on your server.
What’s it Good For?
Before Samba can do anything for us, we need to tell which folders we want it to share. To do that, we need to modify the configuration file for Samba:
$ sudo nano /etc/samba/smb.conf
nano is my preferred Linux text editor, but you’ll find there are a lot of options if you don’t like it and need to update files very often. You’ll see the contents of the config file once you type the command:
We want to scroll down to the very bottom of this file and add some text, starting with [sambashare], like this:
Replace <user_name> with your user name, and <folder_name> with any folder in your user directory you want to share. In a future tutorial, I’ll show the process of mounting a storage hard drive in your server, and you can also point it to that if you want to share an entire drive (which is useful if you need to transfer a lot of media files often). [sambashare] can be any name you’d like, and you can add any comment you’d like as well to help keep this shared folder organized. You can add multiple entries like this to share multiple folders, too.
In nano, to save and quit, hit ctrl-x and then hit y, and then enter. Then, restart Samba with this command:
$ sudo service smbd restart
Before you continue, you’ll need your server’s IP address. One quick way to see it is to use the built in ip command like this:
$ ip address
If you’re like most, you have Windows or MacOS on your laptop or desktop computer. Without a Mac to test myself, I can’t provide any instruction there, but I did find a quick and straightforward guide to the process.
Windows requires a slight change to network security to make this work. First,
On Windows, open an explorer window (Windows Key + E), click on “My PC” and select “Map network drive”. You can add the folder as a network directory, but I’ve found Windows to have a hard time with it unless you modify security settings:
Next, choose a drive letter and type in the server directory path. Remember [sambashare] from earlier? Whatever the name of the share is (in brackets) is what you’ll use for the folder name here. Be sure to select “connect using different credentials”. This option is why we are mapping it as a drive rather than as a shared folder:
Type in your credentials, and you’ll see a new hard drive appear in your window. This is your Linux network folder, and it’s ready to use!