Samba Quick Reference¶
Config file: /etc/samba/smb.conf
Commands¶
# Validate config for errors
testparm
# Show active connections and shares
smbstatus
# Restart after config changes
sudo systemctl restart smbd
# Check service status
sudo systemctl status smbd
User Management¶
Samba users are separate from Linux users. A Linux account must exist first.
# Add samba password for existing Linux user
sudo smbpasswd -a username
# Change samba password
sudo smbpasswd username
# Disable a samba user
sudo smbpasswd -d username
# Enable a disabled user
sudo smbpasswd -e username
# Delete a samba user
sudo smbpasswd -x username
# List all samba users
sudo pdbedit -L
# List with details (SID, full name, etc.)
sudo pdbedit -Lv
Share Configuration¶
Shares are defined in /etc/samba/smb.conf. Each share is a block:
[sharename]
path = /path/to/folder
read only = No
valid users = username
browseable = Yes
create mask = 0644
directory mask = 0755
Common options:
| Option | Purpose |
|---|---|
path |
Directory to share |
read only |
No = writable, Yes = read only |
valid users |
Users allowed access (space separated) |
browseable |
Show in network browse lists |
guest ok |
Allow anonymous access (avoid this) |
create mask |
Permissions for new files |
directory mask |
Permissions for new directories |
force user |
All access treated as this Linux user |
force group |
All access treated as this Linux group |
write list |
Users with write access (when read only = Yes) |
Adding a New Share¶
- Create the directory:
- Add to
/etc/samba/smb.conf:
- Validate and restart:
Mounting from a Client¶
Full walkthrough for a desktop (fstab, credentials file, Dolphin, robustness options): Mounting NAS shares on a desktop.
# Install cifs-utils (Debian/Ubuntu)
sudo apt install cifs-utils
# Create mount point
sudo mkdir -p /mnt/sharename
# Create credentials file
sudo bash -c 'cat > /etc/samba/creds << EOF
username=username
password=yourpassword
EOF'
sudo chmod 600 /etc/samba/creds
# Add to /etc/fstab
//server.<YOUR_LOCAL_DOMAIN>/sharename /mnt/sharename cifs credentials=/etc/samba/creds,uid=1000,gid=1000,iocharset=utf8,_netdev 0 0
# Mount now without reboot
sudo mount -a
Testing¶
# Test access from another machine
smbclient -L //server.<YOUR_LOCAL_DOMAIN> -U username
# Connect to a specific share
smbclient //server.<YOUR_LOCAL_DOMAIN>/sharename -U username
# Verify mount from client side
mount | grep cifs
df -h /mnt/sharename
Troubleshooting¶
# Check logs
sudo tail -f /var/log/samba/log.smbd
# Permission denied on mount: verify samba password is set (smbpasswd -a)
# NT_STATUS_ACCESS_DENIED: check valid users in smb.conf
# Mount hangs: check firewall allows ports 139/445
# Stale mount after server reboot: sudo umount -f /mnt/sharename && sudo mount -a
# Mount hangs only while a desktop VPN is connected: the VPN is routing the NAS's subnet (see below)
Samba uses TCP ports 139 and 445. Both must be reachable from the client.
See also Network mounts that fail at boot and Desktop VPN tunnelling your LAN.