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 -y

Verify the installation:

samba --version

2. 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 sambauser

You will be prompted to set a password. To enable the account:

sudo smbpasswd -e sambauser

2c. Verify Samba users

sudo pdbedit -L

3. Create a Shared Folder

sudo mkdir -p /srv/samba/shared
sudo chown sambauser:sambauser /srv/samba/shared
sudo chmod 770 /srv/samba/shared
  • 770: 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.conf

Back up the original first:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Global settings (review/adjust as needed)

[global]
   workgroup = WORKGROUP
   server string = Samba Server
   security = user
   map to guest = Never
   encrypt passwords = yes

Add 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
OptionDescription
valid usersOnly listed users can access the share
read only = noUsers can read and write
browseable = yesShare is visible when browsing the network
create maskPermissions for new files
directory maskPermissions for new directories

5. Validate the Configuration

testparm

Fix any reported errors before continuing.


6. Restart Samba

sudo systemctl restart smbd nmbd
sudo systemctl enable smbd nmbd

Check status:

sudo systemctl status smbd

7. Allow Samba Through the Firewall

If using ufw:

sudo ufw allow samba
sudo ufw reload

If using firewalld:

sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --reload

8. 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=yourpassword

From 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 sambauser

Disable a Samba user

sudo smbpasswd -d sambauser

Delete a Samba user

sudo smbpasswd -x sambauser

Allow multiple users on a share

valid users = alice, bob, @samba-group

Use @groupname to grant access to an entire Linux group.


10. Tips & Troubleshooting

IssueFix
Permission deniedCheck folder ownership and valid users
Share not visibleEnsure browseable = yes and firewall allows Samba
Authentication failsRe-run smbpasswd -a to reset the Samba password
Config errorsRun testparm to validate smb.conf

See Also