Samba is a suite of open source applications that implements the Server Message Block (SMB) protocol. Many operating systems, including Microsoft Windows, use the SMB protocol for client-server networking. Samba enables Linux / Unix machines to communicate with Windows machines in a network. Samba provides file and print services for various Microsoft Windows clients and can integrate with a Microsoft Windows Server domain, either as a Domain Controller (DC) or as a domain member.
Sharing files is an essential part of server administration. It allows sharing of resources across the network which are needed by users to carry out their tasks. Samba server is usually installed on central Linux server where information is stored in variety of media and accessed using windows client or Linux using Samba client.
In this article, we will be learning how to install and configure samba file sharing on Ubuntu 20.04. Ubuntu 20.04 will be configured as the Samba server then we can access the files with either Windows or Linux clients.
Related Content:
Table of Content
- Ensuring that the server is up to date
- Install samba Packages
- Configuring Samba shares
- Enable Samba service through firewall
- Start and enable the Samba service
- Access Samba shares with Linux Client
- Access Samba shares with Windows client
- Secure Samba share configuration
1. Ensuring that the server is up to date
Before proceeding, let us ensure that our server is up to date and all the packages are the latest version. Use these commands to achieve this:
sudo apt update
sudo apt upgrade -y
If there are packages to upgrade, the above command may take a couple of minutes.
2. Install Samba packages
The samba packages are available in the default Ubuntu repositories. Install them with this command:
sudo apt install samba
When prompted to confirm the installation process, type y then enter to proceed.
We can check if the installation was successful by running:
$ whereis samba
samba: /usr/sbin/samba /usr/lib/x86_64-linux-gnu/samba /etc/samba /usr/share/samba /usr/share/man/man8/samba.8.gz /usr/share/man/man7/samba.7.gz
Confirm the installed software package version with this command:
$ apt-cache policy samba
samba:
Installed: 2:4.13.14+dfsg-0ubuntu0.20.04.4
Candidate: 2:4.13.14+dfsg-0ubuntu0.20.04.4
Version table:
*** 2:4.13.14+dfsg-0ubuntu0.20.04.4 500
500 http://eu-west-3.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
100 /var/lib/dpkg/status
3. Configuring Samba shares
The samba configuration file is located in this path /etc/samba/smb.conf
. Before doing any modification, let us create a backup of it so if we mess we have a copy. Use this command in the terminal to create a backup file:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bk
Next, let us create a directory to be shared.
sudo mkdir -p /home/sambapublicshare
Let us now edit the samba config to define the export for the directory we created.
Open the config file:
sudo vim /etc/samba/smb.conf
Update the configuration in the file to reflect the following:
[Public]
path = /home/sambapublicshare
comment = Citizix Samba Shares
browsable =yes
writable = yes
guest ok = yes
read only = no
Save and close the file.
Verify the configuration using this command:
sudo testparm
You should see something similar to this if all is well.
$ sudo testparm
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters
...
4. Enable Samba service through Firewall
If you have ufw firewall installed and enabled, you need to enable the samba service through firewall. Use this command to achieve that:
sudo ufw allow samba
5. Start and enable the Samba service
The service will not be started by default. Start the service using this command:
sudo systemctl start smbd
Confirm the service status using this:
$ sudo systemctl status smbd
● smbd.service - Samba SMB Daemon
Loaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-01-21 13:27:31 UTC; 5s ago
Docs: man:smbd(8)
man:samba(7)
man:smb.conf(5)
Process: 617106 ExecStartPre=/usr/share/samba/update-apparmor-samba-profile (code=exited, status=0/SUCCESS)
Main PID: 617118 (smbd)
Status: "smbd: ready to serve connections..."
Tasks: 4 (limit: 4624)
Memory: 7.0M
CGroup: /system.slice/smbd.service
├─617118 /usr/sbin/smbd --foreground --no-process-group
├─617123 /usr/sbin/smbd --foreground --no-process-group
├─617124 /usr/sbin/smbd --foreground --no-process-group
└─617125 /usr/sbin/smbd --foreground --no-process-group
Jan 21 13:27:30 ubuntusrv.citizix.com systemd[1]: Starting Samba SMB Daemon...
Jan 21 13:27:31 ubuntusrv.citizix.com update-apparmor-samba-profile[617106]: Reloading updated AppArmor profile for Samba...
Jan 21 13:27:31 ubuntusrv.citizix.com systemd[1]: Started Samba SMB Daemon.
The above output shows that the service has been started successfully. To enable the service on boot, use this command:
sudo systemctl enable smb
6. Access the Samba shares with Linux client
To access the file system from a linux client, we need to have the Samba client software installed.
On a Ubuntu Linux, install the software using this command:
sudo apt install -y samba-client
To access the share, this is the format:
smbclient //server-IP/Public
In our client:
$ smbclient //10.2.11.10/Public
Enter WORKGROUP\ubuntu's password:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Fri Jan 21 13:23:25 2022
.. D 0 Fri Jan 21 13:23:25 2022
50758604 blocks of size 1024. 41160968 blocks available
smb: \>
Since we have no password set, just press enter when prompted.
7. Access Samba shares with Windows Client
In Windows Launch run dialogue in windows by pressing Windows Key + R.

Enter hostname or IP-Address of the server then press Enter Key.
\\hostname
or
\\server-IP-address
In my case
\\35.180.123.111
This will open the shares. You can add a file or directory either from samba server or windows client machine to the repository.

8. Secure Samba share Configuration
Samba allows public access without verification and also private share where one has to be authenticated to access shared resources. In this section, we are going to configure a private directory to shared with samba and accessed using username and password.
Let’s create a Samba user group in our server.
sudo groupadd sambagrp
Create a new user and add it to samba group you just created.
sudo useradd -g sambagrp sambausr
Create a secure folder then grant it relative permissions and ownership .
sudo mkdir -p /home/sambaprivateshare
Create password for Samba user we just created that will be used for authentication when accessing the directory.
sudo smbpasswd -a sambausr
Type and retype the password:
$ sudo smbpasswd -a sambausr
New SMB password:
Retype new SMB password:
Added user sambausr.
Edit samba configuration file to add secure share configurations.
sudo vim /etc/samba/smb.conf
Add lines below the command and edit to match your configurations.
[Private]
path = /home/sambaprivateshare
valid users = @private
guest ok = no
writable = yes
browsable = yes
Restart or reload samba services to apply configurations
sudo systemctl restart smbd
Accessing Samba Secure files using Windows Systems
Press Windows Key + R, enter the server hostname or IP address to access the shared folders.
When you open a private folder will prompt for username and password to grant access right to the files.

Access Samba Secure Directory with Linux
To access secure folder, You need to provide a user to the command using this format:
smbclient //server-IP/Private -U user
Enter Samba user password when prompted.
$ smbclient //10.2.11.10/Private -U sambausr
Enter SAMBA\sambausr's password:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Sat Jan 15 09:02:33 2022
.. D 0 Sat Jan 15 09:02:33 2022
52417516 blocks of size 1024. 48489312 blocks available
smb: \>
That is it! We have managed to install and set up Samba for Anonymous and Secure file sharing between our Ubuntu 20.04 Server and other Linux or Desktop Windows clients.