Learn how to create a Samba share on Linux Ubuntu 20.04 and 22.04 LTS


Share files and directories on Ubuntu using Samba – a network protocol used for file sharing. It’s compatible with both Windows and Linux systems on the network, and it grants read, write, and anonymous access permissions on shared directories. In this article, we’ll show you how to install and use Samba on Ubuntu (versions 20.04 and 22.04).


In order to create Samba shares on Linux Ubuntu the following is a list of items that are needed:
1) A desktop or laptop with 50GB of free disk space, a dual core processor and 4 GB RAM
2) Linux Ubuntu 20.04 or 22.04 LTS
3) An SSH client such as Putty
4) A basic understanding of Linux commands
5) A stable internet connection


The following is a overview of the steps covered in this tutorial:
1) Learn how to download and install Samba.
2) Learn how to create a private Share using Samba.
3) Learn how to create a public Share using Samba.
4) Learn how to access a Samba Share from Linux.
5) Learn how to mount Samba Share on Linux.

Learn how to download and install Samba

The Ubuntu repository has the Samba package installed as a default. You can use the following command for installation:
apt-get install samba samba-common-bin acl -y
After installation, you can start the Samba services and enable them for system reboot by using the following commands:
systemctl start smbd nmbd
systemctl enable smbd nmbd
To verify the version of Samba that is installed, you can use the following command:
smbd --version
The output will show you the version number, which currently is Version

Learn how to create a private share using Samba

Now that Samba is installed on Ubuntu, we will now take you through the process of creating a private share that only authorized users can access. Start by modifying the Samba main configuration file, which can be found at /etc/samba/smb.conf. Then, append the following lines at the end of the file:
comment = private share
path = /data/private/
browseable = yes
guest ok = no
writable = yes
valid users = @samba.
After making changes, save and close the file. Create a new user using the command
adduser user1. 
Once you’ve created the user, set a Samba password with the command
smbpasswd -a user1
Next, create a Samba group using the command
groupadd samba
and add user1 to the samba group using
gpasswd -a user1 samba
Create a shared folder that you have specified in the smb.conf file with
mkdir -p /data/private 
touch /data/private/file1
then provide read and write permissions to the Samba share with
setfacl -R -m "g:samba:rwx" /data/private.
Lastly, test the Samba configuration file for any errors using the command
and restart the Samba service to apply the changes with
systemctl restart smbd nmbd

Learn how to create a public share using Samba

In this section, we will illustrate the process of setting up a public share using Samba, allowing unrestricted access to the share without the need of a username and password. To commence with, you need to modify the main Samba configuration file. Open the configuration file using the nano editor:
nano /etc/samba/smb.conf
Next, add the following lines to the end of the file:
comment = public share
path = /data/public/
browseable = yes
writable = yes
guest ok = yes
After adding the lines, save and exit the configuration file. Now, create a public directory by running the following commands:
mkdir -p /data/public/
touch /data/public/file2
Lastly, ensure that proper permissions are set on the public directory. Execute the following command:
setfacl -R -m "u:nobody:rwx" /data/public
Finally, restart the Samba service by running the following command:
systemctl restart smbd nmbd

Learn how to access a Samba Share from Linux

To access the Samba share from a Linux system, you will need to install the Samba client. To install it, execute the following command:
apt-get install smbclient cifs-utils -y
Once the Samba client is installed, you can access the private share by executing the following command:
smbclient //samba-ip-address/private -U user1
You will be prompted to enter the password for user1. After entering the password, you can list the Samba share by executing the following command:
smb: \> list
To list all the files in the private share directory, execute the following command:
smb: \> ls
After listing the files, exit from the Samba shell using the following command:
smb: \> exit
To connect to the Public share, execute the following command:
smbclient //samba-ip-address/public
You will not be asked to provide a password, just press Enter. After that, list all the files in the Public share by executing the following command:
smb: \> ls
That’s it!

Learn how to mount Samba Share on Linux.

It’s possible to mount a shared directory to the client system, enabling access and use of the directory on the client system. To begin with, create a directory on the client system where you want to mount the Samba
mkdir /mount
Next, mount the Private share directory to the client system by executing the following command:
mount -t cifs -o username=user1 //samba-ip-address/private /mount
You will be required to enter the password of user1 to mount the directory. Enter the password and proceed. After that, verify that the mounted directory is correctly mounted on the /mount directory by executing the following command:
df -h
If mounted correctly, you should see your Private shared directory mounted on the /mount directory. To access the Samba share locally, execute the following command:
ls /mount/
You will see the contents of the directory, including file1. That’s it!


In this guide, you learnt how to install and configure Samba on Ubuntu 20.04 and 22.04, allowing you to share files and directories across your network. You learned how to create both private and public shares, restricting access for the former and offering open access for the latter. Additionally, the tutorial demonstrated techniques for accessing and mounting Samba shares from other Linux systems, providing seamless integration and accessibility.

Remember, the effectiveness of your Samba configuration depends on your specific needs and security considerations. You can customize parameters and permissions based on your desired level of access control and data protection. Don’t hesitate to explore further resources and experiment with different configurations to optimize your Samba setup for your own unique workflows.

We hope this comprehensive guide has empowered you to leverage the power of Samba for efficient file sharing across your Linux systems.

Scroll to Top