A practical masterclass on installing Samba, configuring /etc/samba/smb.conf shares, managing smbpasswd user credentials, validating with testparm, and mounting on Windows and Linux.
In modern heterogeneous corporate environments, enterprise networks rarely run exclusively on Linux or Windows. Workstations commonly run Microsoft Windows 10/11 or macOS, while central file servers, databases, and backup appliances run enterprise Linux. Samba is the open-source software suite that bridges this divide by implementing the Server Message Block (SMB) and Common Internet File System (CIFS) networking protocols.
With Samba, a Linux machine can act as an SMB file server, a network print server, or even a full Microsoft Active Directory Domain Controller (AD DC), allowing Windows and macOS users to drag, drop, and edit files over the network without installing any client software.
Samba consists of two primary system service daemons:
# On Ubuntu / Debian:
sudo apt update
sudo apt install samba samba-common-bin smbclient cifs-utils -y
# On RHEL / Rocky Linux / AlmaLinux / Fedora:
sudo dnf install samba samba-common samba-client cifs-utils -y
Let's create two practical corporate shares: a Public Anonymous Share (read/write for everyone) and a Secured Corporate Share (restricted to authenticated team members):
# 1. Create directory paths
sudo mkdir -p /srv/samba/public
sudo mkdir -p /srv/samba/secured
# 2. Permissions for public share
sudo chown -R nobody:nogroup /srv/samba/public # Ubuntu/Debian
# sudo chown -R nobody:nobody /srv/samba/public # RHEL/Rocky
sudo chmod -R 0777 /srv/samba/public
# 3. Create a dedicated Linux group for secured share access
sudo groupadd smbgroup
sudo chgrp -R smbgroup /srv/samba/secured
sudo chmod -R 0770 /srv/samba/secured
The entire behavior of Samba is governed by /etc/samba/smb.conf. Before editing, always create a clean backup of the default configuration:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
sudo nano /etc/samba/smb.conf
Configure the global parameters and add the share definitions:
[global]
workgroup = WORKGROUP
server string = Linux Samba File Server
security = user
map to guest = bad user
dns proxy = no
log file = /var/log/samba/log.%m
max log size = 1000
# Share 1: Public Read-Write Share (No Password Required)
[Public]
comment = Public Shared Storage
path = /srv/samba/public
browseable = yes
writable = yes
guest ok = yes
guest only = yes
create mask = 0777
directory mask = 0777
# Share 2: Secured Authenticated Share (Restricted to 'smbgroup' members)
[Secured]
comment = Restricted Corporate Storage
path = /srv/samba/secured
browseable = yes
writable = yes
guest ok = no
valid users = @smbgroup
create mask = 0660
directory mask = 0770
Samba authenticates users against its own encrypted database (passdb.tdb). A user must already exist in the Linux system before they can be added to Samba:
# 1. Create a Linux system user without shell login privilege
sudo useradd -M -s /usr/sbin/nologin john
sudo usermod -aG smbgroup john
# 2. Assign a Samba password to the user
sudo smbpasswd -a john
# Enter and confirm password when prompted
# 3. Enable the user in Samba
sudo smbpasswd -e john
smbpasswd Cheat Sheet:
smbpasswd -a <user>: Adds a new Samba user and sets password.smbpasswd -d <user>: Disables a Samba user account.smbpasswd -e <user>: Enables a previously disabled Samba user.smbpasswd -x <user>: Deletes the user from the Samba database.
Always run testparm to verify that there are no typographical syntax errors before restarting the services:
# Check configuration syntax
testparm -s
If testparm outputs Loaded services file OK, start and enable the daemons:
# On Ubuntu / Debian:
sudo systemctl restart smbd nmbd
sudo systemctl enable smbd nmbd
# On RHEL / Rocky / AlmaLinux:
sudo systemctl restart smb nmb
sudo systemctl enable smb nmb
# Ubuntu UFW:
sudo ufw allow samba
# RHEL Firewalld:
sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --reload
\\192.168.1.100 (substituting your Linux server IP) and press Enter.Public and Secured folders. Double-clicking Secured prompts for the Samba credentials created earlier (john and password).Z:): Right-click This PC → Map network drive → \\192.168.1.100\Secured → Check "Reconnect at sign-in".# 1. Inspect remote shares from Linux CLI
smbclient -L //192.168.1.100 -U john
# 2. Mount manually into local directory
sudo mkdir -p /mnt/samba_secured
sudo mount -t cifs //192.168.1.100/Secured /mnt/samba_secured -o username=john
# 3. Mount permanently in /etc/fstab with a secure credentials file
sudo nano /etc/samba/credentials
# Enter:
# username=john
# password=secretpass
sudo chmod 600 /etc/samba/credentials
# Append to /etc/fstab:
# //192.168.1.100/Secured /mnt/samba_secured cifs credentials=/etc/samba/credentials,_netdev,uid=1000,gid=1000 0 0
# Check currently active Samba client connections and open file locks
sudo smbstatus
# Check connected machines and IP addresses
sudo smbstatus --shares
bad user automatically converts invalid or anonymous login attempts to the guest account (unprivileged nobody user). This allows users to access public shares marked with guest ok = yes without being prompted for a username and password.
create mask to set the default Linux octal file permissions (e.g. 0664) and directory mask (e.g. 0775) for new folders, preventing newly created files from having unsafe or unusable permissions on the server.
passdb.tdb), the actual operating system disk operations (reading inodes, writing file blocks, checking Linux POSIX file ownership) are executed by the Linux kernel. Therefore, the kernel must map every authenticated Samba session to a legitimate POSIX UID and GID registered in /etc/passwd.
smbd service is stopped on the server.
browseable = no inside that share's block in smb.conf. The share will not be listed when users browse the server, but users who know the exact path (e.g. \\server\hidden_share$) can still connect directly.