Sub topic 5
Defining Shares and Permissions
This chapter assumes you can use chmod, chown, and systemctl, and that you understand Linux users, groups, and file permissions. A Samba share is a named network entry that points to a directory on the server.
Two permission checks
Samba access depends on two separate checks:
- Samba checks whether the connected user may use the share.
- Linux checks whether that user may access the directory and files.
The request succeeds only when both checks allow it. A Samba setting cannot grant access that Linux permissions deny.
Define a group-controlled share
A share section in /etc/samba/smb.conf starts with its name in brackets. The path setting identifies the exported directory.
[global]
workgroup = WORKGROUP
server role = standalone server
map to guest = never
server min protocol = SMB2
[projects]
path = /srv/samba/projects
read only = no
valid users = @staff
force group = staff
create mask = 0664
directory mask = 0775read only = no permits write operations. valid users = @staff allows only members of the local staff group. The @ means “Unix group.” force group = staff makes new files use staff as their group, even when the user’s primary group differs.
create mask limits the permissions that new files may receive. Here, files can have read and write permissions for the owner and group, and read permission for others. directory mask performs the same limiting function for directories.
Prepare the directory and add a user as follows:
sudo groupadd staff
sudo mkdir -p /srv/samba/projects
sudo chgrp staff /srv/samba/projects
sudo chmod 2775 /srv/samba/projects
sudo useradd -M -s /usr/sbin/nologin -G staff alice
sudo smbpasswd -a aliceThe 2 in 2775 sets the setgid bit. New items inherit the directory’s group, which helps a team collaborate. The Samba password is separate from the Linux login password. The nologin shell prevents this account from starting an interactive Linux session.
Check the effective result
Use testparm before reloading or restarting Samba. It parses the configuration and reports the effective settings:
sudo testparm -sIf a user can authenticate but cannot create a file, inspect both the share settings and the directory’s Unix permissions:
ls -ld /srv/samba/projectsA share configured as writable still fails when the directory is not writable by the authenticated user or group.
Exercise
The share has read only = no, but Alice receives “permission denied” when creating a file. What should you check first?
Show answer
Check that Alice belongs to the allowed staff group and that /srv/samba/projects gives the owner or group write permission. Both Samba rules and Linux permissions must allow the operation.