Samba implements the SMB/CIFS protocol, allowing Ubuntu to act as a file server that Windows, macOS, and other Linux machines can access natively. If you need to share files across a mixed network of Linux and Windows systems, Samba is the standard solution. This guide covers installation, share configuration, user management, and firewall rules on Ubuntu 26.04.
[!TIP] Real-World Scenario: You’re in the office, and the creative lead needs that 4GB video file right now, but Slack is being a snail and we’re too fancy for USB sticks. This is when a rock-solid Samba share becomes the hero of the hour.
sudo apt install samba smbclient— install Samba- Create share directories in
/srv/samba/ - Edit
/etc/samba/smb.confto define shares sudo smbpasswd -a username— add Samba userssudo ufw allow Samba— open firewall- Access shares via
\\server-ip\share-namefrom Windows
Prerequisites
Before you start, you need:
- Ubuntu 26.04 server with sudo access
- A Windows or Linux client on the same network for testing
How do I install Samba?
Ubuntu 26.04 includes Samba in its default repositories. Update your package index and install Samba along with the client tools:
sudo apt update
sudo apt install samba smbclient The samba package provides the server components, while smbclient provides a command-line tool for testing connections.
Verify the Samba service is running:
sudo systemctl status smbd The smbd daemon handles file sharing and authentication. Ubuntu 26.04 ships with disable netbios = yes in the default smb.conf, meaning the nmbd service for legacy NetBIOS name resolution is not required.
Check the installed version:
smbd --version How do I create shared directories?
Create the directories that will serve as shared folders. Set up both a public share (guest access) and a private share (authenticated access).
Public Share Directory
sudo mkdir -p /srv/samba/public_share
sudo chmod 0777 /srv/samba/public_share
echo "Public share ready" | sudo tee /srv/samba/public_share/welcome.txt The 0777 permission allows any user to read, write, and execute within the public directory. This is appropriate for guest-accessible shares where convenience takes priority over strict access control.
Private Share Directory
sudo mkdir -p /srv/samba/private_share
sudo chown $USER:$USER /srv/samba/private_share
sudo chmod 0770 /srv/samba/private_share
echo "Private data" | sudo tee /srv/samba/private_share/confidential.txt
sudo chown $USER:$USER /srv/samba/private_share/confidential.txt The private directory restricts access to the owner and group members only.
How do I configure Samba shares?
The main Samba configuration file is /etc/samba/smb.conf. Before making changes, create a backup:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak Open the configuration file:
sudo nano /etc/samba/smb.conf Add the following share blocks at the bottom of the file:
[public_share]
comment = Public Share for Everyone
path = /srv/samba/public_share
browseable = yes
read only = no
guest ok = yes
force user = nobody
[private_share]
comment = Private Share - Authentication Required
path = /srv/samba/private_share
browseable = yes
read only = no
guest ok = no
valid users = $USER
create mask = 0660
directory mask = 0770 Directive explanations:
comment— Human-readable description of the sharepath— Filesystem path to the shared directorybrowseable— Whether the share appears in network browse listsread only— Set tonoto allow write accessguest ok— Whenyes, no password is required to connectforce user— All file operations performed as the specified uservalid users— Restricts access to the listed users onlycreate mask/directory mask— Permissions for newly created files and directories
Validate the configuration syntax:
testparm If testparm reports no errors, restart the Samba service:
sudo systemctl restart smbd How do I manage Samba users?
Samba maintains its own user database, separate from the system password file. However, each Samba user must first exist as a system user.
If your user doesn’t exist in Samba’s database, add them:
sudo smbpasswd -a $USER You’ll be prompted to enter and confirm a Samba password. This password can differ from the system login password.
Enable the user:
sudo smbpasswd -e $USER List all registered Samba users:
sudo pdbedit -L Managing Samba users:
- Disable a user:
sudo smbpasswd -d username - Remove a user:
sudo smbpasswd -x username
These operations don’t affect the underlying system account.
How do I set up the firewall?
If UFW is active, allow Samba traffic:
sudo ufw allow Samba Verify the rule:
sudo ufw status The Samba UFW profile opens TCP ports 139 and 445 along with UDP ports 137 and 138. Since Ubuntu 26.04 disables NetBIOS by default, only TCP port 445 is strictly required.
To open just the necessary port:
sudo ufw allow 445/tcp Only enable Samba on trusted networks. If your server is exposed to the internet, restrict access by source IP:
sudo ufw allow from 192.168.1.0/24 to any app Samba How do I access the shares?
Test from the Server Using smbclient
Test the public share locally without authentication:
smbclient //localhost/public_share -N The -N flag suppresses the password prompt for guest access. If the connection succeeds, you’ll see the smb: \> prompt. Type ls to list files and exit to disconnect.
Test the private share with authentication:
smbclient //localhost/private_share -U $USER Enter the Samba password when prompted.
Access from a Linux Client
From another Linux machine, install cifs-utils:
sudo apt install cifs-utils Mount the private share:
sudo mkdir -p /mnt/private_share
sudo mount -t cifs //server-ip/private_share /mnt/private_share -o username=$USER You’ll be prompted for the Samba password. After mounting, access the shared files at /mnt/private_share.
To persist the mount across reboots, add an entry to /etc/fstab:
//server-ip/private_share /mnt/private_share cifs credentials=/home/username/.smbcredentials,uid=1000,gid=1000 0 0 Store the username and password in the credentials file with chmod 600 permissions.
Access from a Windows Client
Open File Explorer and type in the address bar:
\\server-ip\private_share Windows will prompt for credentials. Enter your username and Samba password.
For the public share:
\\server-ip\public_share This should be accessible without credentials.
To map the share as a network drive, right-click “This PC” in File Explorer, select “Map network drive,” and enter the share path. This provides persistent access to the share across reboots.
Summary
- Install Samba with
sudo apt install samba smbclient - Create share directories with appropriate permissions
- Configure shares in
/etc/samba/smb.confwithtestparmvalidation - Add Samba users with
sudo smbpasswd -a username - Open firewall with
sudo ufw allow Samba - Access shares from Linux using
smbclientormount -t cifs - Access shares from Windows using
\\server-ip\share-name
FAQ
How do I make a Samba share persist across reboots on a Linux client?
Add an entry to /etc/fstab on the client machine:
//server-ip/private_share /mnt/private_share cifs credentials=/home/username/.smbcredentials,uid=1000,gid=1000 0 0 Store the username and password in the credentials file with restricted permissions (chmod 600).
Why can I not connect to the Samba share from another machine?
First, verify the Samba service is running with sudo systemctl status smbd. Check that your firewall allows Samba traffic using sudo ufw status. Confirm the client and server are on the same network segment and can ping each other.
How do I restrict a Samba share to specific IP addresses?
Add the hosts allow directive to the share definition in /etc/samba/smb.conf:
[private_share]
hosts allow = 192.168.1.0/24 Restart the Samba services after making changes.
Can I use Samba alongside NFS on the same server? Yes, Samba and NFS can coexist on the same Ubuntu 26.04 server and even share the same directories. Samba is typically preferred for Windows clients, while NFS is commonly used in Linux-only environments due to its lower overhead.
What to Read Next
- Install NFS on Ubuntu 26.04 — set up NFS for Linux-only file sharing
- Configure UFW Firewall on Ubuntu — detailed firewall configuration guide
- Install and Configure PHP on Ubuntu 26.04 — configure PHP for web applications
Related Articles
Deepen your understanding with these curated continuations.
Install and Configure Git on Ubuntu 26.04
Complete guide to install Git on Ubuntu 26.04. Configure user identity, generate SSH keys for GitHub/GitLab, master essential workflow commands, and customize with aliases.
Install .deb Packages on Ubuntu 26.04
Complete guide to install .deb packages on Ubuntu 26.04 using apt, dpkg, and GDebi. Handle dependencies, verify installations, and troubleshoot common errors.
Install and Configure PostgreSQL on Ubuntu 26.04
Complete guide to install PostgreSQL 18 on Ubuntu 26.04. Set up roles, databases, remote access, authentication methods, and security hardening.