Sub topic 4
Creating Samba users
This chapter assumes that you can use sudo, create Linux users and groups, edit text files, and manage services with systemctl. You should also understand basic ownership and permission commands such as chown and chmod.
How Samba users work
Samba authenticates users through two related account systems:
- A Linux user account provides a user name and numeric user ID.
- A Samba account stores the password and account state used for SMB authentication.
Creating only a Linux user is not enough. Creating only a Samba entry is also not enough because Samba normally requires a matching local Linux account.
Samba can use different password databases. A common standalone-server choice is tdbsam, which stores account data in a local database. The smbpasswd command updates this database without changing the Linux user's password.
Create a user for Samba
Create the group that will later control access to a share. Then create a Linux account with no home directory and a non-login shell. The account can authenticate to Samba, but it cannot open an interactive Linux session.
sudo groupadd staff
sudo useradd -M -s /usr/sbin/nologin -G staff alice
sudo smbpasswd -a aliceThe -a option adds alice to Samba's password database. The command prompts for a Samba password. This password may differ from the Linux password.
If the Linux account already exists, omit useradd and run only smbpasswd -a username. The account must be enabled before clients can use it:
sudo smbpasswd -e aliceSamba checks the Linux account's group membership when a share uses a group restriction such as valid users = @staff. Add another existing user to the group with:
sudo usermod -aG staff bobThe -aG combination appends the group. Omitting -a can replace the user's other supplementary groups.
Inspect and manage Samba accounts
List Samba accounts with:
sudo pdbedit -LDisable an account temporarily without deleting it:
sudo smbpasswd -d aliceEnable it again with sudo smbpasswd -e alice. Delete the Samba account entry with sudo smbpasswd -x alice; this does not automatically delete the Linux account.
Common errors
Failed to add entry for user: confirm that the Linux user exists.- Authentication fails after adding the user: check the exact user name, Samba account state, and password.
- Access is denied after authentication: check group membership, the share's user restrictions, and filesystem permissions.
- A new group membership is not visible in an existing session: log out and back in, or start a new session.
Exercise
Why does smbpasswd -a alice usually require alice to exist as a Linux user?
Show answer
Samba authenticates the network password, then uses the matching Linux account and its groups when accessing files.