How to Setup Samba Server on Ubuntu 22.04

This article is going to take you through on How to setup samba server on Ubuntu 22.04. Samba is a free software re-implementation of the SMB networking protocol that provides file and print services for a variety of Microsoft Windows clients and can be used as a Domain Controller (DC) or a domain member in a Microsoft Windows Server domain. Samba is compatible with most Unix-like systems, including Linux, Solaris, OpenVMS, AIX, and BSD versions.

Install Samba Server on Ubuntu 22.04

  • Update your packages.
sudo apt update
  • Next install Samba server using the following command.
sudo apt install samba

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  attr ibverbs-providers libcephfs2 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 librados2 librdmacm1 liburing2 python3-dnspython python3-gpg python3-markdown python3-pygments
  python3-requests-toolbelt python3-samba python3-tdb samba-common samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools
Suggested packages:
  python3-sniffio python3-trio python-markdown-doc python-pygments-doc ttf-bitstream-vera bind9 bind9utils ctdb ldb-tools ntp | chrony smbldap-tools winbind heimdal-clients
The following NEW packages will be installed:
  attr ibverbs-providers libcephfs2 libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 librados2 librdmacm1 liburing2 python3-dnspython python3-gpg python3-markdown python3-pygments
  python3-requests-toolbelt python3-samba python3-tdb samba samba-common samba-common-bin samba-dsdb-modules samba-vfs-modules tdb-tools
0 upgraded, 24 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.2 MB of archives.
After this operation, 71.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 python3-dnspython all 2.1.0-1ubuntu1 [123 kB]
Get:2 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 python3-tdb amd64 1.4.5-2build1 [15.5 kB]
Get:3 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 python3-samba amd64 2:4.15.5~dfsg-0ubuntu5 [3,102 kB]
Get:4 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 samba-common all 2:4.15.5~dfsg-0ubuntu5 [71.0 kB]
Get:5 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 samba-common-bin amd64 2:4.15.5~dfsg-0ubuntu5 [616 kB]                                                                                         
Get:6 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 tdb-tools amd64 1.4.5-2build1 [26.2 kB]                                                                                                        
Get:7 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 samba amd64 2:4.15.5~dfsg-0ubuntu5 [1,190 kB]                                                                                                  
Get:8 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 attr amd64 1:2.5.1-1build1 [22.6 kB]                                                                                                           
Get:9 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libibverbs1 amd64 39.0-1 [69.3 kB]                                                                                                             
Get:10 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 ibverbs-providers amd64 39.0-1 [341 kB]                                                                                                       
Get:11 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 librdmacm1 amd64 39.0-1 [71.2 kB]                                                                                                             
Get:12 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 librados2 amd64 17.1.0-0ubuntu3 [3,562 kB]                                                                                                    
Get:13 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libcephfs2 amd64 17.1.0-0ubuntu3 [741 kB]                                                                                                     
Get:14 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libgfxdr0 amd64 10.1-1 [22.1 kB]                                                                                                              
Get:15 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libglusterfs0 amd64 10.1-1 [288 kB]                                                                                                           
Get:16 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libgfrpc0 amd64 10.1-1 [47.1 kB]                                                                                                              
Get:17 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libgfapi0 amd64 10.1-1 [77.3 kB]                                                                                                              
Get:18 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 liburing2 amd64 2.1-2build1 [10.3 kB]                                                                                                         
Get:19 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 python3-gpg amd64 1.16.0-1.2ubuntu4 [215 kB]                                                                                                  
Get:20 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 python3-markdown all 3.3.6-1 [68.5 kB]                                                                                                        
Get:21 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 python3-pygments all 2.11.2+dfsg-2 [750 kB]                                                                                                   
Get:22 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 python3-requests-toolbelt all 0.9.1-1 [38.0 kB] 
  • After the installation Samba server should be up and running.
sudo systemctl status smbd

Sample out

● smbd.service - Samba SMB Daemon
     Loaded: loaded (/lib/systemd/system/smbd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-05-03 10:26:43 EAT; 10min ago
       Docs: man:smbd(8)
             man:samba(7)
             man:smb.conf(5)
    Process: 12043 ExecStartPre=/usr/share/samba/update-apparmor-samba-profile (code=exited, status=0/SUCCESS)
   Main PID: 12052 (smbd)
     Status: "smbd: ready to serve connections..."
      Tasks: 4 (limit: 4588)
     Memory: 16.1M
        CPU: 230ms
     CGroup: /system.slice/smbd.service
             ├─12052 /usr/sbin/smbd --foreground --no-process-group
             ├─12054 /usr/sbin/smbd --foreground --no-process-group
             ├─12055 /usr/sbin/smbd --foreground --no-process-group
             └─12056 /usr/lib/x86_64-linux-gnu/samba/samba-bgqd --ready-signal-fd=45 --parent-watch-fd=11 --debuglevel=0 -F

Mei 03 10:26:43 itnixpro-virtual-machine systemd[1]: Starting Samba SMB Daemon...
Mei 03 10:26:43 itnixpro-virtual-machine update-apparmor-samba-profile[12046]: grep: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Mei 03 10:26:43 itnixpro-virtual-machine update-apparmor-samba-profile[12049]: diff: /etc/apparmor.d/samba/smbd-shares: No such file or directory
Mei 03 10:26:43 itnixpro-virtual-machine systemd[1]: Started Samba SMB Daemon.
  • If for some reasons it’s not running, start and enable it using the command below.
 sudo systemctl enable – now smbd
  • Allow Samba on firewall if you have running firewall.
sudo ufw allow 'Samba'

Configure Samba Share on Ubuntu 22.04

  • Start by creating directory to share.
mkdir demoshare
  • To create password protected shared folder simply set Samba user password using the command below. Note, replace itnixpro with your username preferably your PC username.
sudo smbpasswd -a itnixpro

Sample output

New SMB password:
Retype new SMB password:
Added user itnixpro.
  • After you’ve set the password with the command, enable the samba account.
sudo smbpasswd -e itnixpro
  • Next, in the Samba config file located at /etc/samba/smb.conf, enter the shared folder details.
sudo nano /etc/samba/smb.conf

Add the following with your details i.e. name, users

[demoshare] 
path = /home/itnixpro/demoshare 
read only = no 
valid users = itnixpro 
  • Restart Samba server to apply changes.
sudo systemctl restart smbd

Connect to Samba Share

  • Open file manager.
  • On other locations, enter your Ubuntu IP address running Samba server and share directory e.g. smb://192.168.171.129/demoshare as shown below then click CONNECT button.
  • Next, enter username and password for the shared directory you created previously.
  • The Samba shared directory will now be accessible.

Any operating system can now access the Ubuntu Samba server, check the windows example below.

Connect to Ubuntu Samba Share from Windows 10

  • Open Windows explorer, right click the on the drop menu that will appear select add network location.
  • Network location wizard will pop up, click next to proceed.
  • Choose a custom network location.
  • Then enter shared folder location that was created on Ubuntu 22.04 as shown below.
  • Name your network location.
  • Click finish to complete the setup wizard.
  • Next, enter your shared folder credentials. This is the username and password that was set on Ubuntu shared folder.
  • After successful login, you will be connected to the shared directory. You can now share files from ubuntu to any operating system and vice versa in the same network as demonstrated in the windows 10 example.
  • It’s a wrap! you have reached the end of our article. You have learned how to setup Samba server on Ubuntu 22.04. Cheers!

Read more on Samba Documentation.

Other Tutorials

How to Backup Linux systems using Veeam Agent

Install vnStat network traffic monitor on Rocky Linux

Install vnStat network traffic monitor on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment