Home UbuntuHow to Install and Configure Samba File Sharing on Ubuntu

How to Install and Configure Samba File Sharing on Ubuntu

by Knowledge Base Linux
How to Install and Configure Samba — How to Install and Configure Samba File Sharing on Ubuntu

This article covers How to Install and Configure Samba in detail. Samba on Ubuntu lets a Linux server speak the SMB/CIFS protocol, the file-sharing language Windows uses natively. With Samba on Ubuntu, your server appears in Windows Explorer like any Windows machine, users open shared folders with their own credentials, and macOS and Linux clients connect just as easily. It is the standard answer when a small office asks for “a shared drive” without buying a NAS. In this guide you will install Samba on Ubuntu, create a password-protected share, connect from Windows, and avoid the permission mistakes that cause most failed first attempts.

What Samba on Ubuntu Does – How to Install and Configure Samba

Samba is an open-source implementation of Microsoft’s SMB protocol. The smbd daemon serves files and printers, while nmbd handles name services on the local network. A crucial detail surprises many newcomers: Samba accounts are separate from Linux accounts. A user must exist as a Linux user and also be added to Samba’s own password database before they can log in to a share. Keep that in mind; half of all “access denied” problems are simply a missing Samba password.

Prerequisites – How to Install and Configure Samba

  • An Ubuntu 20.04, 22.04 or 24.04 server or desktop with sudo access.
  • A Windows, macOS or Linux client on the same network (or VPN).
  • The usernames of the people who will access the share.

Step 1: Install Samba

sudo apt update
sudo apt install samba -y
systemctl status smbd

The service starts automatically. Check the configuration syntax any time with testparm -s, which prints the effective configuration and complains about errors.

Step 2: Create the Shared Directory

sudo mkdir -p /srv/shared
sudo groupadd smbshare
sudo chown root:smbshare /srv/shared
sudo chmod 2770 /srv/shared

The 2770 permissions mean only the owner and the smbshare group can enter the directory, and the setgid bit (the leading 2) makes new files inherit the group automatically, so team members keep seeing each other’s uploads.

Home network using Samba on Ubuntu shared folders

Step 3: Define the Share in smb.conf

Back up the original file, then append a share definition to /etc/samba/smb.conf:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
[shared]
   path = /srv/shared
   browseable = yes
   writable = yes
   guest ok = no
   valid users = @smbshare
   create mask = 0660
   directory mask = 2770

valid users = @smbshare restricts the share to the group. Validate the file and restart the service:

testparm -s
sudo systemctl restart smbd

Step 4: Create Samba User Accounts

For each person, create the Linux account (if needed), add them to the group and set their Samba password. The Samba password can differ from the Linux password:

sudo adduser alice
sudo usermod -aG smbshare alice
sudo smbpasswd -a alice

Repeat for every user. List Samba accounts at any time with sudo pdbedit -L.

Step 5: Open the Firewall

If UFW is active, allow the predefined Samba profile, which opens the NetBIOS and SMB ports needed by clients:

sudo ufw allow 'Samba'

The UFW on Ubuntu guide explains profiles and rule ordering if you restrict access to a specific subnet, which is a good idea on larger networks.

Step 6: Connect from Windows and Linux

On Windows, open Explorer, click the address bar and type \\server-ip\shared, then enter the Samba username and password from Step 4. You can map it as a permanent network drive from the right-click menu. On macOS, use Finder → Go → Connect to Server with smb://server-ip/shared. On Linux, browse smb://server-ip/shared in the file manager or test from the terminal:

smbclient //server-ip/shared -U alice -c 'ls'

If your users mainly run Linux clients, also compare with the NFS on Ubuntu setup; NFS is simpler between Linux machines, while Samba wins whenever Windows is in the picture.

Troubleshooting

Windows says “Access denied”. The user is missing from Samba’s database or not in the smbshare group. Verify with pdbedit -L and groups alice, and remember the Linux directory permissions must also allow the group.

The share is visible but files cannot be written. Check both layers: the share’s writable = yes and the filesystem permissions on /srv/shared. Samba can only ever narrow what the filesystem allows.

The server does not appear in the network list. Name browsing is unreliable on modern networks; connect by IP address instead, and check that nmbd is running if you rely on discovery.

Connection times out. The firewall is blocking SMB. Confirm the UFW rule exists and that no router or cloud security group sits between client and server.

One last habit worth adopting: review the account list every few months and remove people who changed teams or left the company, because stale accounts on a file server are an unnecessary risk.

Conclusion

Samba on Ubuntu turns any Ubuntu machine into a friendly file server for mixed networks: install the package, create a group-owned directory, define the share, register users with smbpasswd and open the firewall. Keep guest access off, keep user lists small and explicit, and your shared drive will quietly do its job for years. The official Samba documentation covers advanced topics such as Active Directory membership and printer sharing.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.