MeshWorld India Logo MeshWorld.
samba ubuntu file-sharing smb linux 8 min read

Set Up Samba File Sharing on Ubuntu 26.04

Jena
By Jena
| Updated: Apr 26, 2026
Set Up Samba File Sharing on Ubuntu 26.04

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.

TL;DR
  • sudo apt install samba smbclient — install Samba
  • Create share directories in /srv/samba/
  • Edit /etc/samba/smb.conf to define shares
  • sudo smbpasswd -a username — add Samba users
  • sudo ufw allow Samba — open firewall
  • Access shares via \\server-ip\share-name from 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:

bash
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:

bash
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:

bash
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

bash
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

bash
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:

bash
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Open the configuration file:

bash
sudo nano /etc/samba/smb.conf

Add the following share blocks at the bottom of the file:

ini
[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 share
  • path — Filesystem path to the shared directory
  • browseable — Whether the share appears in network browse lists
  • read only — Set to no to allow write access
  • guest ok — When yes, no password is required to connect
  • force user — All file operations performed as the specified user
  • valid users — Restricts access to the listed users only
  • create mask / directory mask — Permissions for newly created files and directories

Validate the configuration syntax:

bash
testparm

If testparm reports no errors, restart the Samba service:

bash
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:

bash
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:

bash
sudo smbpasswd -e $USER

List all registered Samba users:

bash
sudo pdbedit -L
Information

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:

bash
sudo ufw allow Samba

Verify the rule:

bash
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:

bash
sudo ufw allow 445/tcp
Warning

Only enable Samba on trusted networks. If your server is exposed to the internet, restrict access by source IP:

bash
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:

bash
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:

bash
smbclient //localhost/private_share -U $USER

Enter the Samba password when prompted.

Access from a Linux Client

From another Linux machine, install cifs-utils:

bash
sudo apt install cifs-utils

Mount the private share:

bash
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.

Information

To persist the mount across reboots, add an entry to /etc/fstab:

plaintext
//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:

plaintext
\\server-ip\private_share

Windows will prompt for credentials. Enter your username and Samba password.

For the public share:

plaintext
\\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.conf with testparm validation
  • Add Samba users with sudo smbpasswd -a username
  • Open firewall with sudo ufw allow Samba
  • Access shares from Linux using smbclient or mount -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:

plaintext
//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:

ini
[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.