$ run as a normal user# run as root (or with sudo)
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.
| Item | RHEL / Rocky / Alma | Ubuntu / Debian |
|---|---|---|
| Packages | samba, samba-client (+ cifs-utils on clients) | samba, smbclient, cifs-utils |
| Service | smb.service (and nmb.service for old name browsing) | smbd.service (and nmbd) |
| Config | /etc/samba/smb.conf | the same |
| Check config | testparm | the same |
| Port | 445/tcp (139 only for very old clients) | the same |
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 --reloadInstall on Ubuntu and Debian
apt-get update
apt-get install -y samba smbclient cifs-utils
systemctl enable --now smbd
ufw allow sambaFirst 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 aliceGlobal security settings and the share:
[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| Setting | Why |
|---|---|
server min protocol = SMB3 | No old SMB1/SMB2 (SMB1 is how WannaCry spread). |
smb encrypt = required | All traffic to the server is encrypted. |
map to guest = never, restrict anonymous = 2 | No guest or anonymous access. |
valid users = @finance | Only members of the finance group. |
create mask, directory mask, force group | New files are readable/writable by the group, not by others. |
vfs objects = recycle | Deleted 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.)
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,sealFor /etc/fstab: //files.corp.example.com/finance /mnt/finance cifs credentials=/root/.smb-finance,vers=3.1.1,seal,_netdev,nofail 0 0.
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.smbdReal 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.
Make it safe
Security checklist:
- SMB3 only, encryption and signing required, no guest/anonymous access.
- Groups and
valid usersper share; least privilege on Linux permissions;setgidfolders. - 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).
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
NT_STATUS_LOGON_FAILURE | No Samba password or the account is disabled. | smbpasswd -a USER / smbpasswd -e USER. |
NT_STATUS_ACCESS_DENIED | Not in valid users, Linux permissions, or SELinux. | Check the group; ls -ld; restorecon; ausearch -m avc -ts recent. |
NT_STATUS_BAD_NETWORK_NAME | Wrong share name or the path does not exist. | testparm -s; create the folder. |
| Windows: "The specified network name is no longer available" / protocol errors | Old client vs server min protocol = SMB3. | Update the client (Windows 8.1+/Server 2012+ support SMB3). |
| New files are not editable by colleagues | Masks or group not set. | create mask = 0660, force group, chmod 2770 on the folder. |
Linux mount fails: mount error(13): Permission denied | Wrong credentials or missing seal with smb encrypt = required. | Check the credentials file; add vers=3.1.1,seal. |
Next steps
- Quick how-to: Mount a Windows or Samba share.
- Shares for Linux clients: NFS server. Users and groups: RHCSA — Users.
- Permissions: RH124 — Permissions. The firewall: firewalld.
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.