Updated: 11 October 2026 · Applies to: Samba 4.23.6 on Ubuntu 26.04 LTS, Samba 4.19.5 on Ubuntu 24.04 LTS, Samba 4.22.11 on Debian 13 and Samba 4.23.5 on AlmaLinux 10 (same steps for Rocky Linux and RHEL 9 and 10)
To install Samba on Ubuntu, run sudo apt install samba, give each user a Samba password with sudo smbpasswd -a USERNAME, add a share section to /etc/samba/smb.conf, check it with testparm and restart the service with sudo systemctl restart smbd. Windows, macOS and Linux computers can then open the folder at \\SERVER-IP\share (or smb://SERVER-IP/share). The steps below set up a password-protected share for a group of users on Ubuntu 24.04 and 26.04, then list what differs on AlmaLinux, Rocky Linux and RHEL.
Security first: never open SMB (TCP port 445) to the whole internet. Allow only your office or VPN addresses, as in step 6. To reach files from anywhere, connect through a VPN such as WireGuard, or use SFTP instead.
Install and configure Samba on Ubuntu
- Install the server and the command-line client, then check the version:
sudo apt update sudo apt install samba smbclient smbd --version
Our Ubuntu 26.04 test printedVersion 4.23.6-Ubuntu-4.23.6+dfsg-1ubuntu2.2; Ubuntu 24.04 printedVersion 4.19.5-Ubuntu. - Create a group, the shared folder and a Linux user for each person. The user does not need a shell login:
sudo groupadd smbusers sudo mkdir -p /srv/samba/share sudo chgrp smbusers /srv/samba/share sudo chmod 2770 /srv/samba/share sudo useradd -M -s /usr/sbin/nologin -G smbusers alice
The2in2770makes new files inherit thesmbusersgroup. - Give the user a Samba password. Samba keeps its own password list, separate from the Linux password:
sudo smbpasswd -a alice sudo pdbedit -L
smbpasswd asks for the new SMB password twice and printsAdded user alice.;pdbedit -Lthen listedalice:1001:. More user commands are in how to add, list and delete Samba users. - Back up the configuration file, then edit it:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak sudo nano /etc/samba/smb.conf
Add ahosts allowline under the existing[global]line with your own addresses, and the share at the end of the file:[global] hosts allow = 127.0.0.1 203.0.113.10 192.168.1.0/24 [share] path = /srv/samba/share valid users = @smbusers writable = yes browseable = yes create mask = 0660 directory mask = 2770
valid users = @smbuserslets in only members of that group. According to the smb.conf manual,hosts allowin[global]applies to every share. - Check the file:
testparm
It must printLoaded services file OK., then waits atPress enter to see a dump of your service definitions. Read the lines above it too: a typo such aswrtiable = yesgaveUnknown parameter encountered: "wrtiable"in our test, yet testparm still said OK and simply ignored the line. - Open the firewall for your addresses only, if UFW is active (see how to set up UFW):
sudo ufw allow from 203.0.113.10 to any port 445 proto tcp
The Samba package also installs a UFW profile namedSamba(UDP 137 and 138, TCP 139 and 445), sosudo ufw allow from 192.168.1.0/24 to any app Sambaopens all four for a local network. What each port does: Samba ports 445, 139, 137 and 138. - Start Samba, or restart it after every change to
smb.conf, and check that it runs:sudo systemctl restart smbd systemctl status smbd
The package enablessmbd(andnmbd) at boot. On Ubuntu 26.04nmbdis skipped on purpose, because the default file setsdisable netbios = yes. - Test on the server:
smbclient -L localhost -U alice smbclient //localhost/share -U alice -c 'ls'
The first command lists the shares, the second the files inshare. If you getdo_connect: Connection to localhost failed (Error NT_STATUS_CONNECTION_REFUSED), smbd is not running: see Samba service will not start.
The default Samba configuration on Ubuntu
A fresh Ubuntu 26.04 install starts with these active lines in /etc/samba/smb.conf (shortened: the password-sync lines and the [printers] and [print$] sections are left out):
[global] workgroup = WORKGROUP disable netbios = yes server string = %h server (Samba, Ubuntu) log file = /var/log/samba/log.%m max log size = 1000 server role = standalone server map to guest = bad user usershare allow guests = yes
- Ubuntu 24.04 and Debian 13 do not have the
disable netbios = yesline, sonmbdruns there for old-style network browsing. testparm -svshows every setting including built-in defaults. On Ubuntu 24.04 and 26.04 and on AlmaLinux 10 it reportedserver min protocol = SMB2_02: the old SMB1 protocol is off, and Windows 10 and 11 and current macOS connect over SMB2 or SMB3.- Logs are in
/var/log/samba/, one file per client (log.%m).
AlmaLinux, Rocky Linux and RHEL: what is different
- Packages and services:
sudo dnf install samba samba-client; the services are calledsmbandnmband are not enabled automatically:sudo systemctl enable --now smb. - Default file:
workgroup = SAMBA,security = user, a[homes]share andinclude = /etc/samba/usershares.conf. Steps 2 to 5 above work unchanged (tested on AlmaLinux 10.2). - Firewall (firewalld), for one address:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10/32" service name="samba" accept' sudo firewall-cmd --reload
Thesambaservice opens TCP 139 and 445 and includessamba-client. - SELinux: label the folder, or Samba cannot read it:
sudo semanage fcontext -a -t samba_share_t "/srv/samba/share(/.*)?" sudo restorecon -Rv /srv/samba/share
Ifsemanageis missing, installpolicycoreutils-python-utils.
Guest (no password) shares and home folders are covered in Samba guest and home shares on AlmaLinux, Rocky Linux and RHEL.
Connect to the share from other computers
- Windows: type
\\SERVER-IP\sharein the File Explorer address bar and sign in asalice. To keep it as a drive letter, Microsoft’s steps for Windows 11 are: select This PC, then More > Map network drive, enter the path in the Folder box, tick Reconnect at sign-in and select Finish. A Samba server does not always show up under Network; connecting by address always works, and thewsddpackage (“Python Web Services Discovery Daemon, Windows Net Browsing”) can make it visible there. - macOS: according to Apple, in the Finder choose Go > Connect to Server and enter
smb://SERVER-IP/share. - Linux with smbclient (an FTP-like SMB client):
smbclient -L //SERVER-IP -U alicelists the shares andsmbclient //SERVER-IP/share -U aliceopens ansmb:\>prompt wherels,cd,getandputwork. - Linux, mounted as a folder: install
cifs-utils(apt or dnf), then:sudo mkdir -p /mnt/share sudo mount -t cifs //SERVER-IP/share /mnt/share -o username=alice,uid=$(id -u),gid=$(id -g)
To mount it at boot, put the login in a file only root can read,/root/.smb-alice, with the linesusername=aliceandpassword=YOUR-PASSWORD(chmod 600), and add this line to/etc/fstab://SERVER-IP/share /mnt/share cifs credentials=/root/.smb-alice,uid=1000,gid=1000,_netdev 0 0
According to the mount.cifs manual, current kernels negotiate SMB 2.1 or newer by default.
Common problems
- NT_STATUS_CONNECTION_REFUSED: smbd is not running on that server; check
systemctl status smbd(smbon AlmaLinux). - NT_STATUS_LOGON_FAILURE: the user has no Samba password yet, or the wrong one. Run
sudo smbpasswd -afor them and checksudo pdbedit -L. - NT_STATUS_ACCESS_DENIED when listing files on AlmaLinux, Rocky Linux or RHEL: the SELinux label is missing. Also check the folder’s group and permissions.
- Windows cannot find the server: check
hosts allowand the firewall rule, and connect by IP address instead of by name. - Changes to smb.conf have no effect: run
testparm, then restart smbd (or smb).
Official documentation: Setting up Samba as a standalone server (Samba Wiki) and Samba as a file server (Ubuntu Server documentation).
Ucartz services for this topic
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
