How to Set Up Samba File Sharing on Ubuntu 26.04

Setting up Samba file sharing on Ubuntu 26.04 enables seamless file exchange between Linux and Windows systems on your local network. Samba implements the SMB/CIFS protocol, allowing Ubuntu to act as a file server that Windows, macOS, and other Linux machines can access natively. In this tutorial, you will perform a complete samba setup on Ubuntu 26.04, covering installation, share configuration, user management, and firewall rules.

Software Requirements

CategoryRequirements, Conventions or Software Version Used
SystemUbuntu 26.04 Resolute Raccoon
SoftwareSamba
OtherPrivileged access to your Linux system as root or via the sudo command. A Windows or Linux client on the same network for testing.
Conventions# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Install Samba on Ubuntu 26.04

The first step in the samba setup on Ubuntu 26.04 is to install the Samba package from the 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 to SMB shares. After installation, verify that the Samba service is running:

$ sudo systemctl status smbd

The smbd daemon handles file sharing and authentication. Note that 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. The smbd service is enabled automatically upon installation. You can additionally verify the installed Samba version with:

$ smbd --version

Create a Samba Share Directory

Before configuring Samba, create the directories that will serve as shared folders. In this example, we will create two shares: a public share accessible to all network users without authentication and a private share requiring login credentials.

  1. Create the public share directory:$ sudo mkdir -p /srv/samba/linuxconfig_share $ sudo chmod 0777 /srv/samba/linuxconfig_share $ echo “Greetings from LinuxConfig.org!” | sudo tee /srv/samba/linuxconfig_share/welcome.txt The 0777 permission allows any user to read, write, and execute within the public directory. This is appropriate for a guest-accessible share where convenience takes priority over strict access control. The test file will help verify that the share is working correctly later.
  2. Create the private share directory:$ sudo mkdir -p /srv/samba/linuxconfig_private $ sudo chown linuxconfig:linuxconfig /srv/samba/linuxconfig_private $ sudo chmod 0770 /srv/samba/linuxconfig_private $ echo “Private data from LinuxConfig.org” | sudo tee /srv/samba/linuxconfig_private/confidential.txt $ sudo chown linuxconfig:linuxconfig /srv/samba/linuxconfig_private/confidential.txt The private directory is owned by the linuxconfig user and restricts access to the owner and group members only. The test file will confirm that authenticated access works as expected.

Configure Samba Shares on Ubuntu 26.04

The main Samba configuration file is /etc/samba/smb.conf. Before making changes, create a backup of the original configuration:

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

Now open the configuration file in your preferred text editor and add share definitions at the end of the file:

$ sudo nano /etc/samba/smb.conf

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

[linuxconfig_share]
comment = LinuxConfig Public Share
path = /srv/samba/linuxconfig_share
browseable = yes
read only = no
guest ok = yes
force user = nobody

[linuxconfig_private]
comment = LinuxConfig Private Share
path = /srv/samba/linuxconfig_private
browseable = yes
read only = no
guest ok = no
valid users = linuxconfig
create mask = 0660
directory mask = 0770

Here is what each directive does in the share definitions:

  • comment – A human-readable description of the share.
  • path – The filesystem path to the shared directory.
  • browseable – Controls whether the share appears in network browse lists.
  • read only – Set to no to allow write access.
  • guest ok – When set to yes, no password is required to connect.
  • force user – All file operations in the public share are performed as the nobody user.
  • valid users – Restricts access to the listed users only.
  • create mask and directory mask – Control the permissions assigned to newly created files and directories.

After saving the file, validate the configuration syntax using the testparm utility:

$ testparm

If testparm reports no errors, your configuration is syntactically correct. Consequently, restart the Samba services to apply the changes:

$ sudo systemctl restart smbd

Set Up 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 the linuxconfig user does not already exist on your system, add the user first:

$ sudo adduser linuxconfig

Then set a Samba password for the user. This password is used exclusively for SMB authentication and can differ from the system login password:

$ sudo smbpasswd -a linuxconfig

You will be prompted to enter and confirm the new Samba password. After setting the password, enable the user in the Samba database:

$ sudo smbpasswd -e linuxconfig

To list all registered Samba users, run:

$ sudo pdbedit -L

MANAGING SAMBA USERS
You can disable a Samba user without deleting them using sudo smbpasswd -d linuxconfig. To remove a user entirely from the Samba database, use sudo smbpasswd -x linuxconfig. These operations do not affect the underlying system account.

Configure Firewall for Samba

If UFW is active on your Ubuntu 26.04 system, you need to allow the necessary ports for Samba traffic. UFW includes a pre-defined application profile for Samba, which makes this straightforward:

$ sudo ufw allow Samba

Verify the rule was added:

$ sudo ufw status

The Samba UFW profile opens TCP ports 139 and 445 along with UDP ports 137 and 138. However, since Ubuntu 26.04 disables NetBIOS by default (disable netbios = yes in smb.conf), only TCP port 445 is strictly required. If you prefer to open just the necessary port rather than using the application profile, you can run:

$ sudo ufw allow 445/tcp

SECURITY CONSIDERATION
Only enable Samba on trusted networks. If your server is exposed to the internet, consider restricting access by source IP using sudo ufw allow from 192.168.178.0/24 to any app Samba to limit connections to your local subnet.

Test and Access Samba Shares

With Samba configured and the firewall open, you can now test access to your shares. There are several methods to connect from both Linux and Windows clients.

Test from the Server Using smbclient

Use smbclient to test the public share locally without authentication:

$ smbclient //localhost/linuxconfig_share -N

The -N flag suppresses the password prompt for guest access. If the connection is successful, you will see the smb: \> prompt. Type ls to list files and exit to disconnect.

To test the private share with authentication:

$ smbclient //localhost/linuxconfig_private -U linuxconfig

Enter the Samba password when prompted. A successful connection confirms that both authentication and share access are working correctly.

Access from a Linux Client

From another Linux machine on the same network, you can mount the Samba share using the cifs-utils package. First, install the required package on the client:

$ sudo apt install cifs-utils

Then mount the private share:

$ sudo mkdir -p /mnt/linuxconfig_private
$ sudo mount -t cifs //192.168.178.79/linuxconfig_private /mnt/linuxconfig_private -o username=linuxconfig

You will be prompted for the Samba password. After mounting, you can access the shared files at /mnt/linuxconfig_private.

Access from a Windows Client

On a Windows machine, open File Explorer and type the following in the address bar:

\\192.168.178.79\linuxconfig_private

Windows will prompt you for credentials. Enter linuxconfig as the username and the Samba password you set earlier. For the public share, navigate to \\192.168.178.79\linuxconfig_share, which should be accessible without credentials.

Alternatively, you can map the share as a network drive by right-clicking “This PC” in File Explorer, selecting “Map network drive,” and entering the share path. This provides persistent access to the share across reboots.

Conclusion

You have successfully completed a samba setup on Ubuntu 26.04, creating both public and authenticated file shares accessible from Linux and Windows clients. The configuration covered Samba installation, share directory creation, smb.conf configuration, user management, and firewall rules. For more advanced configurations, including domain integration and printer sharing, consult the official Samba documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *