Samba File Sharing Guide
A step-by-step guide to setting up Samba on Linux, creating protected shares, and managing users.
Prerequisites
- A Linux system (Debian/Ubuntu used in examples)
sudo/ root access- Basic familiarity with the terminal
1. Install Samba
sudo apt update
sudo apt install samba -yVerify the installation:
samba --version2. Create a Samba User
Samba has its own password database separate from the Linux system passwords.
2a. Create a Linux system user (if not already existing)
sudo useradd -M -s /sbin/nologin sambauser-M: do not create a home directory-s /sbin/nologin: prevent shell login (Samba-only account)
2b. Add the user to Samba and set a password
sudo smbpasswd -a sambauserYou will be prompted to set a password. To enable the account:
sudo smbpasswd -e sambauser2c. Verify Samba users
sudo pdbedit -L3. Create a Shared Folder
sudo mkdir -p /srv/samba/shared
sudo chown sambauser:sambauser /srv/samba/shared
sudo chmod 770 /srv/samba/shared770: owner and group have full access; others have none.
4. Configure the Share in smb.conf
Open the Samba configuration file:
sudo nano /etc/samba/smb.confBack up the original first:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bakGlobal settings (review/adjust as needed)
[global]
workgroup = WORKGROUP
server string = Samba Server
security = user
map to guest = Never
encrypt passwords = yesAdd your share definition at the bottom
[Shared]
comment = Protected Shared Folder
path = /srv/samba/shared
valid users = sambauser
read only = no
browseable = yes
create mask = 0660
directory mask = 0770| Option | Description |
|---|---|
valid users | Only listed users can access the share |
read only = no | Users can read and write |
browseable = yes | Share is visible when browsing the network |
create mask | Permissions for new files |
directory mask | Permissions for new directories |
5. Validate the Configuration
testparmFix any reported errors before continuing.
6. Restart Samba
sudo systemctl restart smbd nmbd
sudo systemctl enable smbd nmbdCheck status:
sudo systemctl status smbd7. Allow Samba Through the Firewall
If using ufw:
sudo ufw allow samba
sudo ufw reloadIf using firewalld:
sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --reload8. Connect to the Share
From Linux
# List available shares
smbclient -L //SERVER_IP -U sambauser
# Connect interactively
smbclient //SERVER_IP/Shared -U sambauser
# Mount the share
sudo mount -t cifs //SERVER_IP/Shared /mnt/samba -o username=sambauser,password=yourpasswordFrom Windows
Open File Explorer and enter in the address bar:
\SERVER_IP\Shared
Enter the Samba username and password when prompted.
From macOS
In Finder: Go → Connect to Server and enter:
smb://SERVER_IP/Shared
9. Managing Users
Change a Samba user’s password
sudo smbpasswd sambauserDisable a Samba user
sudo smbpasswd -d sambauserDelete a Samba user
sudo smbpasswd -x sambauserAllow multiple users on a share
valid users = alice, bob, @samba-groupUse @groupname to grant access to an entire Linux group.
10. Tips & Troubleshooting
| Issue | Fix |
|---|---|
| Permission denied | Check folder ownership and valid users |
| Share not visible | Ensure browseable = yes and firewall allows Samba |
| Authentication fails | Re-run smbpasswd -a to reset the Samba password |
| Config errors | Run testparm to validate smb.conf |
See Also
- index — Home
man smb.conf— full configuration reference- Samba documentation