SMB (Server Message Block) is a network protocol for file, printer, and serial port sharing; Samba is the open-source implementation that brings full SMB support to Linux, including Active Directory domain controller capabilities.
Addresses below are RFC 5737 documentation ranges or placeholders - swap in your own.
Table of Contents#
- Overview
- SMB Protocol Versions
- Samba 4 as Active Directory Replacement
- Server Installation
- Basic Share Configuration
- User Management
- Encryption and Security
- VFS Modules
- Performance Tuning
- Audit Logging
- Client Configuration
- Windows Interoperability
- Troubleshooting
- See Also
- Sources
1. Overview#
SMB is an application-layer network protocol originally developed by IBM and later extended by Microsoft. It provides shared access to files, printers, and named pipes between network nodes. The protocol operates primarily over TCP port 445 (direct hosting) and optionally over TCP port 139 (NetBIOS session service, legacy).
Samba is the standard open-source SMB implementation for Linux and other UNIX-like systems. It enables:
- File and printer sharing with Windows, macOS, and Linux clients
- Active Directory domain controller functionality (Samba 4)
- Winbind integration for mapping Windows users to UNIX accounts
- NT-style ACLs and Windows Security Descriptor support
2. SMB Protocol Versions#
| Version | Introduced With | Key Features |
|---|---|---|
| SMB 1.0 / CIFS | Windows NT 4.0 | Original protocol; insecure, no encryption; deprecated, disable in production |
| SMB 2.0 | Windows Vista | Reduced chattiness, compound requests, larger reads/writes |
| SMB 2.1 | Windows 7 | Oplock leasing, large MTU support |
| SMB 3.0 | Windows 8 / Server 2012 | End-to-end encryption, SMB Direct (RDMA), transparent failover, SMB Multichannel |
| SMB 3.0.2 | Windows 8.1 | Improved cluster support |
| SMB 3.1.1 | Windows 10 / Server 2016 | Pre-authentication integrity (SHA-512), AES-128-GCM encryption, mandatory secure negotiation |
SMB 3.1.1 Features#
SMB 3.1.1 is the current recommended protocol version. Key improvements:
- Pre-authentication integrity - SHA-512 hash chain prevents man-in-the-middle downgrades during negotiation
- AES-128-GCM and AES-256-GCM encryption - faster authenticated encryption (replacing AES-128-CCM)
- Mandatory secure negotiation - server can refuse connections that do not negotiate securely
- POSIX extensions - optional POSIX byte-range locks, case-sensitive filenames, symlink support (used by Linux clients)
Enforcing Minimum Version#
# /etc/samba/smb.conf [global]
server min protocol = SMB3_00
client min protocol = SMB3_003. Samba 4 as Active Directory Replacement#
Samba 4 can function as a full Active Directory Domain Controller, providing:
- Kerberos KDC - Heimdal Kerberos for authentication
- LDAP directory - integrated LDB database compatible with AD LDAP schema
- DNS - integrated DNS server or BIND DLZ backend
- Group Policy - basic GPO support
- Schema extensions - AD schema replication from Windows DCs
Provisioning an AD DC#
# Install Samba with AD DC support
sudo apt install -y samba smbclient winbind krb5-user
# Provision the domain
sudo samba-tool domain provision \
--use-rfc2307 \
--realm=EXAMPLE.COM \
--domain=EXAMPLE \
--server-role=dc \
--dns-backend=SAMBA_INTERNAL \
--adminpass='<password>'
# Start the Samba AD DC service
sudo systemctl enable --now samba-ad-dcJoining an Existing AD Domain (as member server)#
sudo samba-tool domain join EXAMPLE.COM MEMBER \
-U Administrator --realm=EXAMPLE.COMLimitation: Samba 4 AD DC does not yet support AD trust relationships with full forest trust, and schema compatibility may vary with newer Windows Server versions. Test thoroughly before replacing a Windows DC in production.
4. Server Installation#
Debian/Ubuntu#
sudo apt update
sudo apt install -y sambaRHEL/CentOS/Rocky#
sudo dnf install -y samba samba-common samba-clientArch Linux#
sudo pacman -S sambaEnable and Start#
sudo systemctl enable --now smbd nmbd5. Basic Share Configuration#
Edit /etc/samba/smb.conf:
[global]
workgroup = WORKGROUP
server string = Samba File Server
security = user
map to guest = never
server min protocol = SMB3_00
[shared]
path = /srv/samba/shared
browsable = yes
read only = no
valid users = @smbusers
create mask = 0664
directory mask = 0775Validate and apply:
# Check for syntax errors
testparm
# Restart services
sudo systemctl restart smbdCommon Share Parameters#
| Parameter | Description |
|---|---|
path | Filesystem path to share |
browsable | Whether the share appears in network browsing |
read only | If yes, clients cannot write |
valid users | Users or groups (@group) allowed to connect |
write list | Users or groups with write access (overrides read only = yes) |
create mask | Default permissions for new files |
directory mask | Default permissions for new directories |
guest ok | Allow anonymous access (use with caution) |
force user | Run all operations as this UNIX user |
force group | Run all operations as this UNIX group |
vfs objects | Load VFS modules for this share |
6. User Management#
Samba maintains its own user database (passdb) separate from the system password file.
# Add a Samba user (must already exist as a system user)
sudo smbpasswd -a <username>
# Enable a disabled user
sudo smbpasswd -e <username>
# Disable a user
sudo smbpasswd -d <username>
# Delete a Samba user
sudo smbpasswd -x <username>
# List Samba users
sudo pdbedit -L -vUsing tdbsam (Default Backend)#
The default tdbsam backend stores credentials in /var/lib/samba/private/passdb.tdb. For larger deployments, consider LDAP-backed passdb via ldapsam.
7. Encryption and Security#
Transport Encryption#
# /etc/samba/smb.conf [global]
# Require encryption for all connections (SMB 3.0+)
server smb encrypt = required
# Per-share encryption
[confidential]
path = /srv/samba/confidential
smb encrypt = requiredEncryption options:
| Value | Behavior |
|---|---|
off | No encryption |
desired | Encrypt if client supports it |
required | Reject connections that do not encrypt |
Signing#
# Require message signing to prevent tampering
server signing = mandatory
client signing = mandatoryRestricting Protocols#
# Disable insecure protocols
server min protocol = SMB3_00
client min protocol = SMB3_00
# Restrict to SMB 3.1.1 only
server min protocol = SMB3_11
server max protocol = SMB3_11Restricting Network Access#
# Only allow connections from specific subnets
hosts allow = 192.0.2.0/24 198.51.100.0/24
hosts deny = ALL8. VFS Modules#
VFS (Virtual File System) modules extend Samba's functionality by intercepting filesystem operations. Modules are loaded per-share or globally.
| Module | Purpose |
|---|---|
vfs_fruit | macOS compatibility (resource forks, Finder metadata, Time Machine) |
vfs_recycle | Recycle bin for deleted files |
vfs_shadow_copy2 | Windows "Previous Versions" via snapshots (ZFS, BTRFS, LVM) |
vfs_acl_xattr | Store NT ACLs in extended attributes |
vfs_full_audit | Comprehensive audit logging of all operations |
vfs_catia | Character mapping for Windows-illegal filename characters |
vfs_glusterfs | Serve GlusterFS volumes directly via libgfapi |
vfs_ceph | Serve CephFS volumes directly via libcephfs |
vfs_zfsacl | Native ZFS ACL support |
vfs_streams_xattr | Store NTFS alternate data streams in extended attributes |
vfs_crossrename | Allow rename across filesystem boundaries |
vfs_worm | Write Once Read Many enforcement |
Example: macOS Time Machine Share#
[timemachine]
path = /srv/samba/timemachine
browsable = yes
read only = no
valid users = @tmusers
vfs objects = fruit streams_xattr
fruit:time machine = yes
fruit:time machine max size = 500GExample: Recycle Bin#
[shared]
path = /srv/samba/shared
vfs objects = recycle
recycle:repository = .recycle/%U
recycle:keeptree = yes
recycle:versions = yes
recycle:maxsize = 09. Performance Tuning#
Socket Options#
# /etc/samba/smb.conf [global]
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072Note: On modern kernels with auto-tuning, overly specific socket options can reduce performance. Test with and without custom settings.
SMB Multichannel#
SMB Multichannel (SMB 3.0+) aggregates bandwidth across multiple network interfaces:
# Enable multichannel (enabled by default in Samba 4.15+)
server multi channel support = yesRequirements: multiple NICs or multiple IP addresses on both server and client.
Asynchronous I/O#
# Use kernel AIO for better throughput
aio read size = 1
aio write size = 1Oplocks and Leases#
Opportunistic locks allow clients to cache data locally, reducing network round trips:
# These are enabled by default; verify they are not disabled
oplocks = yes
level2 oplocks = yesLarge Read/Write Sizes#
# Increase maximum read/write chunk size
max xmit = 65535
read raw = yes
write raw = yesGeneral Recommendations#
| Setting | Value | Reason |
|---|---|---|
use sendfile | yes | Kernel-level file transfer, bypasses userspace |
min receivefile size | 16384 | Use splice for large writes |
getwd cache | yes | Cache current directory lookups |
strict locking | auto | Only check locks on contention |
10. Audit Logging#
vfs_full_audit#
Provides detailed logging of file operations for compliance and security monitoring.
[audited-share]
path = /srv/samba/audited
vfs objects = full_audit
full_audit:prefix = %u|%I|%m|%S
full_audit:success = connect disconnect mkdir rmdir open rename unlink write
full_audit:failure = connect open rename unlink write
full_audit:facility = local5
full_audit:priority = noticeThe prefix format tokens:
| Token | Meaning |
|---|---|
%u | Username |
%I | Client IP address |
%m | Client NetBIOS name |
%S | Share name |
Configuring Syslog#
# /etc/rsyslog.d/samba-audit.conf
local5.notice /var/log/samba/audit.logsudo systemctl restart rsyslogSimple Logging#
For basic access logging without the full audit module:
# /etc/samba/smb.conf [global]
log file = /var/log/samba/log.%m
max log size = 10000
log level = 111. Client Configuration#
Linux CIFS Mount#
# Install the CIFS client utilities
sudo apt install -y cifs-utils
# Mount a share
sudo mount -t cifs //server/shared /mnt/share \
-o username=<user>,password=<password>,vers=3.1.1Using a Credentials File#
# /root/.smbcredentials (chmod 600)
username=<user>
password=<password>
domain=WORKGROUPsudo mount -t cifs //server/shared /mnt/share \
-o credentials=/root/.smbcredentials,vers=3.1.1Persistent Mount via fstab#
//server/shared /mnt/share cifs credentials=/root/.smbcredentials,vers=3.1.1,_netdev,uid=1000,gid=1000 0 0Automount with systemd#
# /etc/systemd/system/mnt-share.mount
[Unit]
Description=SMB Share Mount
After=network-online.target
Wants=network-online.target
[Mount]
What=//server/shared
Where=/mnt/share
Type=cifs
Options=credentials=/root/.smbcredentials,vers=3.1.1,_netdev
[Install]
WantedBy=multi-user.targetsmbclient#
# Browse shares on a server
smbclient -L //server -U <user>
# Interactive session
smbclient //server/shared -U <user>12. Windows Interoperability#
Setting Up SMB on Windows#
- Open Control Panel and navigate to Network and Sharing Center
- Click Change advanced sharing settings
- Enable Network Discovery and File and Printer Sharing
- Right-click the folder to share, select Properties, then the Sharing tab
- Click Advanced Sharing, check Share this folder, and configure permissions
Connecting to a Linux SMB Share from Windows#
\\server\sharedEnter the Samba username and password when prompted.
Permissions Model#
SMB uses a dual-layer permissions model:
- Share permissions - defined in
smb.conf(read only,write list,valid users) - Filesystem permissions - standard UNIX permissions or POSIX/NFSv4 ACLs
The most restrictive permission applies. For Windows-compatible ACLs, use:
[global]
vfs objects = acl_xattr
map acl inherit = yes
store dos attributes = yes13. Troubleshooting#
| Issue | Cause | Solution |
|---|---|---|
NT_STATUS_ACCESS_DENIED on connect | User not in Samba passdb, wrong password, or share permissions | Run smbpasswd -a <user>; verify valid users in share config |
NT_STATUS_BAD_NETWORK_NAME | Share name misspelled or share not defined | Check smb.conf share name; run testparm to validate config |
| Connection timeout | Firewall blocking TCP 445 or 139 | Open ports: firewall-cmd --add-service=samba --permanent |
| Slow performance | SMB version mismatch, no multichannel, small buffers | Enforce modern protocol: server min protocol = SMB3_00; check socket options |
| Permission denied when writing | UNIX filesystem permissions more restrictive than share | Check and adjust chown/chmod on the share path; verify create mask and force user |
| macOS clients cannot connect | Missing fruit VFS module or protocol mismatch | Add vfs objects = fruit streams_xattr to the share |
| Windows "Previous Versions" not working | shadow_copy2 not configured or snapshots not available | Configure vfs objects = shadow_copy2; set shadow:snapdir and verify snapshots exist |
smbclient works but mount fails | Missing cifs-utils package | Install: apt install cifs-utils or dnf install cifs-utils |