Ubuntu Samba: How to install and configure it?

Samba is an open-source suite that offers fast file sharing using the SMF/CIFS protocol between different Operating Systems, such as Linux, Windows, and others. The Samba name comes from SMB (Server Message Block), a proprietary protocol used by the Microsoft Windows network file system. In this tutorial, we will show you how to install and configure Ubuntu Samba so you can share files over the network. Let’s begin.

Step 1: Update Ubuntu Packages

Before you start the installation on your Samba VPS server, update the packages first. You can do this with the following command:

# apt update && sudo apt upgrade

Step 2: Install Samba

You can install Samba using the apt package manager with the command:

# apt install samba

To check if Samba was successfully installed and the Samba version you can use run:

# apt install samba

This will show the Samba version, which at the time of writing is 4.19.5

You can also check if Samba is running with the systemctl command:

# systemctl status smbd

Step 3. The Samba config file

You will need to create a shared directory, which will be used for file sharing.

This can be done simply using the command:

# mkdir -p /home/shared

The shared directory will be created in the /home directory now.

To configure the Sharing service, you should modify the settings in /etc/samba/smb.configure

In this file, you will need to set the following parameters:

workgroup = WORKGROUP

server string = samba-sharing

You can leave the work = WORKGROUP default option, and the server string will be the description field for the Samba server.

Once you have configured these parameters, you must configure the networking parameters.

First, you will need to check the interfaces on your server:

# ip link

This will show all the network interfaces available on your server. Our system’s interfaces are lo (loopback interface) and enp0s3 network interface.

You can now set them with:

interfaces = lo enp0s3

Also, don’t forget to enable the bind interfaces and usershare allowing the guests option.

bind interfaces only = yes
usershare allow guests = yes

Then you can save the file and test the samba configuration file for syntax errors with the:

# testparm

Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
…

If you receive the output Load services file OK from the testparm utility, then no syntax errors were detected in the Samba configuration file.

Step 4. Samba user and sharing directory

To create a Samba user, a system user should have the same username. You can go ahead and create the Linux system user first with:

# adduser john

You will be prompted to enter this user’s password and other fields. Once the user is created you now you can create the Samba user John with:

# smbpasswd -a john

You can create as many users as you need with the same command smbpasswd -a john

Now, you can create the Samba share directory or use an existing directory if you already have one. For this example, we will use the Samba directory in /home

First, let’s create the directory:

# mkdir -p /home/samba

Then, you will need to change the permissions to this directory. You can do this with the command:

# chown -R nobody:sambashare /home/samba

Step 5. Configuring the Ubuntu Samba server

Now that you have the samba share directory and the samba users created, you will add your configuration block in the /etc/samba/smb.conf

You can navigate to the end of the file and add the following settings.


We have added the valid user = @john so only the user john will be able to connect to the samba sharing directory, if you remove this line and enable the guest ok option, than any user on this network will be able to access the Samba Network Sharing directory.
Now save the file and once again perform the testparm action to test for syntax errors.

[sharing]
comment = Samba share directory
path = /home/samba
read only = no
writable = yes
browseable = yes
guest ok = no
valid user = @john

If there are no syntax errors in the configuration, go ahead and restart the Samba service.

# systemctl restart smbd

Now, to test the Samba share configuration, you can try to connect from a Linux or Windows Machine.

If you are using Windows as your client machine you can open “This PC” then click on the Link bar on the top and enter the, IP address of your Samba Sharing Server in this format \\192.168.x.x
If you followed the instructions and the Samba server is configured properly you should be able to see the “sharing” directory that you previously configured.

Now, if you left the option valid users = @john, you will be asked to log in as a user, and only the user john will be allowed to access the network sharing directory. Once you are prompted to log in, enter the Samba username and password that you previously added. In this case, it was the user john, and you will access the shared directory on your Linux server from a Windows machine.

Congratulations: You’ve installed Ubuntu Samba

That’s it. You successfully installed and configured the Ubuntu Samba server on your Linux machine.

PS. If you liked this post, please share it with your friends or leave a comment below.

Leave a Comment