Samba, a free, open-source utility of SMB networking protocol, enables file sharing between Linux machines and other operating systems. And Server Message Block(SMB) allows Samba clients to connect and access the files and directories remotely. In this article, I have outlined step-by-step procedures of installing, configuring and connecting a Samba client on Ubuntu. Let’s go over it & grasp the basics.
Key Takeaways
- Understanding Samba, Samba client.
- Learning about the installation and configuration procedure of Samba.
- Learning how to connect a Samba client on Ubuntu.
- Understanding the fact of mounting & unmounting Samba shares.
Requirements
- Make sure you have Ubuntu installed on your PC.
- You must have root/sudo privileges.
- A text editor(This article uses nano).
Process Flow Chart
[Distro Used Throughout the Tutorial: Ubuntu 22.04.2 LTS]
Watch How to Install, Configure and Connect Samba Client on Ubuntu
Installing Samba on Ubuntu
The Samba package is available on Ubuntu’s official repositories. Here I will show you how to install Samba on Ubuntu.
Steps to Follow >
➊ First, open the Ubuntu terminal & install the apt packages by executing the following command
sudo apt-get update
sudo apt install samba
➌ Now, you can check if you have installed Samba successfully or not with the command below:
whereis samba
- whereis: Returns the source, binary and manual page files of given commands.
- samba: Free packages.
mkdir /home/nadiba/sambashare
- mkdir: Creates one or more directories.
- /home/nadiba/sambashare: Indicates ‘sambashare’ directory inside the home directory of user “nadiba”.
Read More: How to Install and Configure Samba Server in Ubuntu? [4 Steps]
Configuring Samba on Ubuntu
After the installation process, you need to configure Samba on Ubuntu by following the steps below:
Steps to Follow >
➊ Type according to the following command to open the configuration file for Samba:
sudo nano /etc/samba/smb.conf
- sudo: Super User DO.
- nano: It’s a text editor.
- /etc/samba/smb.conf: Enters into the Samba configuration file under the “etc” directory.
comment = Samba on Ubuntu
path = /home/nadiba/sambashare
read only = no
browsable = yes
- path: It’s the path to the Samba share of the user.
- read only: Users are able to write in this share by setting it to “no”.
- browsable: Other users will be able to browse the share by setting it to “yes”.
➌ Then, save it by pressing “CTRL+O” and “ENTER”. Then, type “CTRL+X” to exit. Once done restart the Samba services using the command below:
sudo service smbd restart
- sudo: Super User DO.
- service: The services sudo provides.
- smbd restart: Restart Samba service.
sudo ufw allow samba
- sudo: Super User DO.
- ufw: Uncomplicated Firewall.
- allow samba: Allows ‘samba’ profile.
➍ Add a user to Samba database by setting & re-confirming new user password for Samba like the following. Here, I have added the user “nadiba”, you can add any of your likings.
sudo smbpasswd -a nadiba
- sudo: Super User DO.
- smbpasswd: Samba encrypted password file.
- -a nadiba: Indicates the user.
sudo smbpasswd -e nadiba
- -e nadiba: Enables the user.
Read More: How to Configure NFS Server in Linux? [5 Steps]
As a Linux user, you can access the Samba share using the command line & mount the Samba share. Now, to get the IP address of the Samba server type the following command and copy the IP address:
ifconfig
- ifconfig: Configures a network interface.
To install ifconfig run the below command:
sudo apt install new-tools
- sudo: Super User DO.
- apt: Advanced package utility.
- install new-tools: Install ‘ifconfig’ command under new-tools.
A. Using Samba Client
First, you need to install the Samba client packages before accessing Samba share. So, follow the given steps.
Steps to Follow >
➊ Install Samba client by running the following command:
sudo apt install smbclient
- sudo: Super User DO.
- apt: Advanced package utility.
- install smbclient: Install Samba client.
smbclient //192.168.211.128/sambashare -U nadiba
- smbclient: Samba client.
- 192.168.211.128: Samba server IP address you copied using ifconfig.
- sambashare Shared folder on Samba server.
- -U nadiba: valid username on Samba server.
- cd <Folder_Name>: Changes directory on Samba share.
- mkdir <Folder_Name>: Creates a directory on Samba share.
- ls: Lists the contents of the directory.
By following the steps below you can mount Samba Share as a local file system on your Ubuntu.
Steps to Follow >
➊ First, install cifs-utils package to mount Samba share.
sudo apt install cifs-utils
- sudo: Super User DO.
- install cifs-utils: Install the in-kernel CIFS file system which depends on a package of user space tools.
sudo mkdir /mnt/smbmount
- sudo: Super User DO.
- mkdir:Creates directory on Samba share.
- /mnt/smbmount: Local directory where you will mount the Samba share.
sudo mount -t cifs -o username=nadiba //192.168.211.128/sambashare /mnt/smbmount
- sudo: Super User DO.
- mount: Attaches a removable file system or storage device to a directory.
- -t: Indicates file system type.
- cifs: Common Internet File System.
- -o: Specifies additional options.
- username=nadiba: Username[you can choose any of your choice].
- 192.168.211.128: IP address of Samba server.
- sambashare: Shared directory on Samba server.
- /mnt/smbmount: Local directory where you will mount the Samba share.
Read More: How to Access Samba Share from Windows [2 Methods]
Complementary Information
Alongside learning about the installation, configuration and connecting procedure of Samba, you will find the below section quite impactful.
How to Configure the Global Samba Options on Ubuntu
To configure global Samba options follow the steps below:
Steps to Follow >
➊ Open the Samba configuration file in a text editor running:
sudo nano /etc/samba/smb.conf
- sudo: Super User DO.
- nano: It’s a text editor.
- /etc/samba/smb.conf: Enters into the Samba configuration file under the “etc” directory.
workgroup = WORKGROUP
security = user
server string = %h server (Samba, Ubuntu)
- workgroup: Sets workgroup name for Samba.
- security: Sets security mode for Samba. For most cases, the default mode is ‘user’.
- server string: Sets the string displayed in the Windows browser for Samba server.
Set the ‘server role’ to standalone server like the following:
server role = standalone server
- server role: The default Samba package file is configured for ‘standalone server’. It means the Samba server is not a member of the Windows domain.
To see the interface name and bind interface type:
interfaces = 192.0.0.0/8 eth0
bind interfaces only = yes
- interfaces: Shows interface name or IP address.
- bind interface: Means only bind to the interfaces given above.
If you want to control the unsuccessful attempts, set ‘map to guest’ as bad user like below:
map to guest = bad user
- map to guest: Controls how unsuccessful authentication attempts are mapped. For most cases, the default mode is set to ‘bad user’.
To set ‘log file’, type the following option:
log file = /var/log/samba/log.%m
- log file: Tells Samba to use a separate log file for each machine. By default, it is set like the image below.
sudo systemctl restart smbd
- sudo: Super User DO.
- systemctl restart smbd: Restarts Samba service.
Read More: Install, Configure and Connect Samba on Ubuntu Using GUI
If you want to unmount a Samba client on Ubuntu, follow the steps carefully:
Steps to Follow >
➊ Use the command ‘mount’ to list all mounted shares:
mount
- mount: Attaches a removable file system or storage device to a directory.
sudo umount /mnt/smbmount
- sudo: Super User DO.
- umount: Detach all removable file systems or storage devices from directory.
- /mnt/smbmount: Local directory where you will mount the Samba share.
mount
Now, you will see there is no line like the output of mounted shares.
How to Set Max and Min Protocol for Samba Client on Ubuntu
In the Samba configuration file, the client max protocol controls the highest protocol version & the client min protocol controls the lowest protocol version which the client attempts to use. So, to set the client protocol version, follow the steps below:
Steps to Follow >
➊ Open the Samba configuration file.
sudo nano /etc/samba/smb.conf
- sudo: Super User DO.
- nano: It’s a text editor.
- /etc/samba/smb.conf: Enters into the Samba configuration file under the “etc” directory.
client max protocol = SMB3
client min protocol = SMB2
- client max protocol: This explains that Samba client will negotiate the maximum SMB protocol version usage.
- SMB3: Samba version 3.
- client min protocol: This explains that Samba client will negotiate the minimum SMB protocol version usage.
- SMB2: Samba version 2.
sudo systemctl restart smbd
- sudo: Super User DO.
- systemctl restart smbd: Restarts Samba service.
Conclusion
By now, you have the proper understanding of how to install, configure and connect a Samba client on Ubuntu. Also, you can mount and unmount Samba shares very easily. Just be conscious of making a backup always before editing any kind of configuration file.
People Also Ask
Related Articles