Advanced
Searching inInstall guides
How to search
  • Paste an error message in quotes, e.g. "permission denied", to find the fix table that explains it.
  • Choose an area and a part of the guide (install, first settings, daily use, security, fixes) to go straight to the right step.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

Guide 78Samba · Network

Install and set up Samba (Windows file shares)

Samba lets a Linux server share folders with Windows, macOS and Linux clients over SMB — the same protocol as Windows file servers. Offices use it for department shares, scanners drop files on it, and apps exchange files with Windows systems through it. This guide installs Samba on RHEL and Ubuntu, makes a secure group share (SMB3, encryption, no guests), handles Linux permissions and SELinux, connects Windows and Linux clients, and covers the common access errors.

  • 10 Lessons
  • 16 Commands

$ run as a normal user# run as root (or with sudo)

78.1

Know it before you install

A share is a folder published under a name (\\files\finance). Access needs both: Samba allows the user (users and valid users), and Linux permissions on the folder allow it (owner, group, mode, SELinux). Samba users have their own SMB passwords (smbpasswd) unless the server joins Active Directory.

ItemRHEL / Rocky / AlmaUbuntu / Debian
Packagessamba, samba-client (+ cifs-utils on clients)samba, smbclient, cifs-utils
Servicesmb.service (and nmb.service for old name browsing)smbd.service (and nmbd)
Config/etc/samba/smb.confthe same
Check configtestparmthe same
Port445/tcp (139 only for very old clients)the same

78.2

Install on RHEL, Rocky, Alma and Fedora

dnf -y install samba samba-client
systemctl enable --now smb
firewall-cmd --permanent --add-service=samba
firewall-cmd --reload

78.3

Install on Ubuntu and Debian

apt-get update
apt-get install -y samba smbclient cifs-utils
systemctl enable --now smbd
ufw allow samba

78.4

First configuration: a secure group share

Make the group, the folder and the Linux permissions — the setgid bit keeps the group on new files:

groupadd finance
usermod -aG finance alice
mkdir -p /srv/shares/finance
chown root:finance /srv/shares/finance
chmod 2770 /srv/shares/finance
smbpasswd -a alice
smbpasswd -e alice

Global security settings and the share:

/etc/samba/smb.conf
[global]
    workgroup = CORP
    server string = File server
    server min protocol = SMB3
    smb encrypt = required
    server signing = mandatory
    map to guest = never
    restrict anonymous = 2
    disable netbios = yes
    smb ports = 445
    log file = /var/log/samba/log.%m
    max log size = 10000
    logging = file
 
[finance]
    path = /srv/shares/finance
    valid users = @finance
    read only = no
    browseable = yes
    create mask = 0660
    directory mask = 2770
    force group = finance
    vfs objects = recycle
    recycle:repository = .recycle
    recycle:keeptree = yes
SettingWhy
server min protocol = SMB3No old SMB1/SMB2 (SMB1 is how WannaCry spread).
smb encrypt = requiredAll traffic to the server is encrypted.
map to guest = never, restrict anonymous = 2No guest or anonymous access.
valid users = @financeOnly members of the finance group.
create mask, directory mask, force groupNew files are readable/writable by the group, not by others.
vfs objects = recycleDeleted files go to .recycle — easy undo for users.

SELinux on RHEL must allow Samba to share the folder:

semanage fcontext -a -t samba_share_t '/srv/shares(/.*)?'
restorecon -Rv /srv/shares
testparm -s
Loaded services file OK.
systemctl restart smb

(Ubuntu: restart smbd; no SELinux step.)

78.5

Connect clients

Windows: in Explorer type \\files.corp.example.com\finance, log in as alice (or map a drive: net use F: \\files\finance /user:alice).

Linux, one time and permanent (with a protected credentials file):

smbclient -L //files.corp.example.com -U alice
smbclient //files.corp.example.com/finance -U alice -c 'ls'
printf 'username=alice\npassword=ALICE_PASSWORD\n' > /root/.smb-finance && chmod 600 /root/.smb-finance
mkdir -p /mnt/finance
mount -t cifs //files.corp.example.com/finance /mnt/finance -o credentials=/root/.smb-finance,uid=1000,gid=1000,vers=3.1.1,seal

For /etc/fstab: //files.corp.example.com/finance /mnt/finance cifs credentials=/root/.smb-finance,vers=3.1.1,seal,_netdev,nofail 0 0.

78.6

Daily use: the commands and the real uses

testparm -s
smbstatus
smbstatus -S
pdbedit -L -v | head
smbpasswd -d bob
smbcontrol all reload-config
tail -f /var/log/samba/log.smbd

Real uses at work:

  • Department and project shares for Windows users on a Linux server.
  • Scan-to-folder from printers; file exchange with Windows apps.
  • With Active Directory: join the server (realm join / net ads join) so users log in with their AD accounts.

78.7

Make it safe

Security checklist:

  • SMB3 only, encryption and signing required, no guest/anonymous access.
  • Groups and valid users per share; least privilege on Linux permissions; setgid folders.
  • SELinux contexts instead of turning SELinux off.
  • Port 445 only from internal networks/VPN — never from the internet.
  • Back up shares (and keep the recycle folder small); audit logs (vfs objects = full_audit) for sensitive shares.
  • Keep Samba updated; disable accounts of people who leave (smbpasswd -d).

78.8

Update and remove

dnf -y upgrade samba
apt-get install --only-upgrade -y samba
systemctl restart smb
dnf -y remove samba

78.9

Fix common problems

ProblemCauseFix
NT_STATUS_LOGON_FAILURENo Samba password or the account is disabled.smbpasswd -a USER / smbpasswd -e USER.
NT_STATUS_ACCESS_DENIEDNot in valid users, Linux permissions, or SELinux.Check the group; ls -ld; restorecon; ausearch -m avc -ts recent.
NT_STATUS_BAD_NETWORK_NAMEWrong share name or the path does not exist.testparm -s; create the folder.
Windows: "The specified network name is no longer available" / protocol errorsOld client vs server min protocol = SMB3.Update the client (Windows 8.1+/Server 2012+ support SMB3).
New files are not editable by colleaguesMasks or group not set.create mask = 0660, force group, chmod 2770 on the folder.
Linux mount fails: mount error(13): Permission deniedWrong credentials or missing seal with smb encrypt = required.Check the credentials file; add vers=3.1.1,seal.

78.10

Next steps

1Access needs two things to allow it. Which?

Samba (valid users, SMB password) and the Linux permissions (and SELinux) on the folder.

2Why set server min protocol = SMB3?

Old SMB1/SMB2 versions are weak; SMB1 was used by WannaCry.

All commands in this chapter