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

  1. 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 printed Version 4.23.6-Ubuntu-4.23.6+dfsg-1ubuntu2.2; Ubuntu 24.04 printed Version 4.19.5-Ubuntu.
  2. 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
    The 2 in 2770 makes new files inherit the smbusers group.
  3. 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 prints Added user alice.; pdbedit -L then listed alice:1001:. More user commands are in how to add, list and delete Samba users.
  4. 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 a hosts allow line 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 = @smbusers lets in only members of that group. According to the smb.conf manual, hosts allow in [global] applies to every share.
  5. Check the file:
    testparm
    It must print Loaded services file OK., then waits at Press enter to see a dump of your service definitions. Read the lines above it too: a typo such as wrtiable = yes gave Unknown parameter encountered: "wrtiable" in our test, yet testparm still said OK and simply ignored the line.
  6. 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 named Samba (UDP 137 and 138, TCP 139 and 445), so sudo ufw allow from 192.168.1.0/24 to any app Samba opens all four for a local network. What each port does: Samba ports 445, 139, 137 and 138.
  7. 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 enables smbd (and nmbd) at boot. On Ubuntu 26.04 nmbd is skipped on purpose, because the default file sets disable netbios = yes.
  8. 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 in share. If you get do_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 = yes line, so nmbd runs there for old-style network browsing.
  • testparm -sv shows every setting including built-in defaults. On Ubuntu 24.04 and 26.04 and on AlmaLinux 10 it reported server 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 called smb and nmb and are not enabled automatically: sudo systemctl enable --now smb.
  • Default file: workgroup = SAMBA, security = user, a [homes] share and include = /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
    The samba service opens TCP 139 and 445 and includes samba-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
    If semanage is missing, install policycoreutils-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\share in the File Explorer address bar and sign in as alice. 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 the wsdd package (“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 alice lists the shares and smbclient //SERVER-IP/share -U alice opens an smb:\> prompt where ls, cd, get and put work.
  • 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 lines username=alice and password=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 (smb on AlmaLinux).
  • NT_STATUS_LOGON_FAILURE: the user has no Samba password yet, or the wrong one. Run sudo smbpasswd -a for them and check sudo 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 allow and 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

Was this answer helpful? 0 Users Found This Useful (0 Votes)