In this tutorial, we will be showing you how to install and configure the Samba server on the Ubuntu operating system.
Samba is a re-implementation of the SMB networking protocol that Windows uses for its file and printer sharing.
By installing the Samba server to the Ubuntu operating system, it will be able to talk and interact with Windows systems easily. It even supports integrating with Microsoft Windows server domain.
The following sections will show you how to install and configure Samba to set up your own Samba shares.
Additionally, these steps should work on all versions of the Ubuntu operating system. This means you can install Samba on Ubuntu 22.04, 20.04. and more.
You will complete the steps within this tutorial within Ubuntu’s terminal. You can open the terminal on the desktop flavor by pressing CTRL + ALT + T on your keyboard.
Installing Samba on Ubuntu
In this section, we will be showing you how to install Samba to the operating system. The Samba package is available in the standard Ubuntu repository, so this process is relatively straightforward.
1. Before you attempt to install a new package such as Samba, you should always perform an update of the package list.
Since Ubuntu uses the apt package manager, updating this list is as simple as using the following command within the terminal.
sudo apt update
Updating the package list is essential to reduce the chance of running into errors or installing an older version of Samba.
2. Once the package list update completes, you can move on to installing Samba to Ubuntu.
Within the terminal, run the following command to install Samba from the package repositories.
sudo apt install samba
You will be prompted whether you want to install this package and its dependencies. To proceed with the installation, type in Y and then press the ENTER key.
3. If you are running a firewall such as UFW, you will need to allow it through the firewall.
You can use the following command to allow Samba through your firewall if you use UFW on your system.
sudo ufw allow samba
If you are using a different firewall, you will need to allow ports
445 using the TCP protocol and ports
138 using the UDP protocol.
4. At this point, you will have now successfully installed Samba to the Ubuntu operating system.
Even though it is installed, you will have to do some initial configuration, such as setting up a Samba share.
Configuring a Samba Share on Ubuntu
With Samba now installed on our Ubuntu operating system, we can move on to configuring it.
This section will touch on modifying the Samba configuration file to add your Samba shares.
Editing the Config File
1. To modify the configuration of Samba, you will want to edit the config file located at “
We will begin editing this file using the nano text editor, as shown in the command below.
sudo nano /etc/samba/smb.conf
Setting the Samba Work Group
By default, Samba will be configured as a part of the “
WORKGROUP” (Typical default on Windows) workgroup. If you are unsure what a workgroup is, it is typically safe to skip this section.
2. The first setting that you might want to change for Samba on your Ubuntu device is the workgroup setting.
To adjust the workgroup Samba joins, you will want to find the following line within the file.
workgroup = WORKGROUP
You can find lines faster when using nano by using CTRL + W, typing in what you are looking for, and then pressing the ENTER key.
3. Once you have found this line, you must replace “
WORKGROUP” with the name of your workgroup/domain.
Creating a Samba Share on Ubuntu
Samba supports creating both public and private shares on your Ubuntu system. A private share is one that requires a username and password to be accessible.
Please note for a private share you will need to set a separate password for your user so you can access Samba shares remotely. We will explore exactly how this is done later on in the guide.
3. Creating a share is a straightforward process with Samba and involves adding a new section to the bottom of the file, as shown below.
Our example will focus on creating a private share on our Ubuntu system. However, as you will see, adjusting this to be a public share is a straightforward process.
[pimylifeupshare] comment = Samba Share on Ubuntu browseable = yes read only = no guest ok = no path = /home/pimyubu/sambashare
[pimylifeupshare] – The first part of every new share is the header. This defines that the following options belong to this specific share and also specifies the name of the share.
The name of the share is situated between the two square brackets (
[ ]). You will use this name when accessing this share from another device.
For example, with the share name of “
pimylifeupshare“, you would access this by going to an address like the following:
comment – You can use the comment option to give your samba share a description. While not required, it can make it easier to identify later.
browseable – This option can be set to “
yes” or “
no“. By setting this to “
yes“, this Ubuntu Samba share will be viewable by others on the network.
If you set the “
browseable” option to “
no“, you will be required to enter the network path manually.
guest ok – With this option, you can allow unauthenticated users to access this share by setting it to “
Alternatively, to require a username and password, you will want to set this option to “
no“, as we have in the example above.
path – The final option and one of the most important is the path option. With this option, you will specify the directory on your Ubuntu system that you want to be shared through Samba.
For our example, we will use a directory located at “
4. Once you have finished creating any additional Samba shares, you can save and quit out of the file.
You can quit and save by pressing CTRL + X, followed by Y, then finally the ENTER key.
Adding a New User to Samba
If you created a new private Samba share on your Ubuntu device, you would need to give your user an SMB password.
The Samba server does not utilize the same passwords for users. Instead, you must use a special tool to set a specific password.
5. To assign your Ubuntu user a password for Samba, you will need to use the “
To use smbpasswd to set a password for your user, you will need to use the following command. Make sure that you replace “
USERNAME” with your username.
sudo smbpasswd -a USERNAME
By using the “
-a” option, we are telling Samba that we are adding the specified user as a new SMB user.
6. Upon running the above command, you will be immediately prompted to type in a new SMB password for this user.
To ensure you don’t make a mistake, you will be required to retype this password after first pressing ENTER.
New SMB password: Retype new SMB password:
7. If you have successfully set a password for your account, you should see the following message printed to the terminal.
Added user USERNAME
Restarting Samba for Changes to Take Effect
You must restart the service whenever you make changes to Samba on your Ubuntu device. If you don’t restart the service, it will not be aware of any changes you have made.
8. To restart Samba we will be utilizing the “systemctl” tool to restart the service.
All you need to do to restart Samba using systemctl is to use the following command within the terminal.
sudo systemctl restart smbd
9. Once Samba finishes restarting, you will now be able to access all of your newly set up Samba shares.
Typically, you will access these shares
Throughout this tutorial, we have shown you how to install and configure Samba on the Ubuntu operating system.
As mentioned, Samba is a server that re-implements the SMB protocol used by Windows operating systems. Using this, you can easily share files or printers from your system to Windows devices.
Please comment below if you have run into any issues getting Samba installed and running.