Learn how to create a Samba share on Linux Ubuntu 20.04 and 22.04 LTS
Introduction
Requirements
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
Overview
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
apt-get install samba samba-common-bin acl -yAfter 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 nmbdTo verify the version of Samba that is installed, you can use the following command:
smbd --versionThe output will show you the version number, which currently is Version
4.11.6-Ubuntu.
Learn how to create a private share using Samba
[Private]After making changes, save and close the file. Create a new user using the command
comment = private share
path = /data/private/
browseable = yes
guest ok = no
writable = yes
valid users = @samba.
adduser user1.Once you’ve created the user, set a Samba password with the command
smbpasswd -a user1Next, create a Samba group using the command
groupadd sambaand add user1 to the samba group using
gpasswd -a user1 sambaCreate a shared folder that you have specified in the smb.conf file with
mkdir -p /data/privatethen provide read and write permissions to the Samba share with
touch /data/private/file1
setfacl -R -m "g:samba:rwx" /data/private.Lastly, test the Samba configuration file for any errors using the command
testparmand restart the Samba service to apply the changes with
systemctl restart smbd nmbd
Learn how to create a public share using Samba
nano /etc/samba/smb.confNext, add the following lines to the end of the file:
[Public] comment = public share path = /data/public/ browseable = yes writable = yes guest ok = yesAfter 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/file2Lastly, ensure that proper permissions are set on the public directory. Execute the following command:
setfacl -R -m "u:nobody:rwx" /data/publicFinally, restart the Samba service by running the following command:
systemctl restart smbd nmbd
Learn how to access a Samba Share from Linux
apt-get install smbclient cifs-utils -yOnce the Samba client is installed, you can access the private share by executing the following command:
smbclient //samba-ip-address/private -U user1You 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: \> listTo list all the files in the private share directory, execute the following command:
smb: \> lsAfter listing the files, exit from the Samba shell using the following command:
smb: \> exitTo connect to the Public share, execute the following command:
smbclient //samba-ip-address/publicYou 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: \> lsThat’s it!
Learn how to mount Samba Share on Linux.
share: mkdir /mountNext, mount the Private share directory to the client system by executing the following command:
mount -t cifs -o username=user1 //samba-ip-address/private /mountYou 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 -hIf 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!
Conclusion
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.