Sub topic 3
Anatomy of `smb.conf`
This chapter assumes you can edit files as root, understand Linux users, groups, and permissions, and manage services with systemctl. You should also know basic IP addressing and how to install Samba packages.
Samba reads its main configuration from /etc/samba/smb.conf. The file is divided into sections. A section starts with a name in square brackets. The special [global] section sets server-wide behavior. Every other section normally defines a share that clients can access.
The configuration structure
A parameter has a name, an equals sign, and a value. Indentation is optional. Comments begin with # or ;.
[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 = 0775The share name is projects. Clients refer to it as //server-name/projects. The path parameter maps that name to a directory on the server.
The read only = no setting permits writes at the Samba layer. Linux permissions must also permit the authenticated user to write. Both permission systems must allow an operation.
The valid users parameter limits access. The @staff form means members of the Linux group named staff. You can list several users or groups, separated by spaces.
force group = staff makes new files and directories use the staff group where possible. The masks limit permissions for newly created objects. They do not change permissions on objects that already exist.
Global settings and share settings
Global parameters apply to the whole Samba server unless a share overrides them. Share parameters apply only inside that share. A setting in a share section takes precedence over the corresponding global default.
Keep global settings for server-wide policy, such as the minimum SMB protocol version. Put paths, access rules, and write behavior in share sections.
Common configuration mistakes
- Writing
read only = nobut forgetting Linux directory permissions. - Using a share path that does not exist.
- Allowing a group in
valid usersbefore adding the intended user to that group. - Setting
map to guest = bad user, which can hide authentication mistakes by treating unknown users as guests. - Enabling old protocol versions to support obsolete clients. Prefer SMB2 or newer.
- Changing the file without validating it or restarting or reloading Samba.
After editing the file, validate its syntax before applying it:
sudo testparm -s
sudo systemctl reload smbdtestparm reports parsing errors and displays the effective configuration. A reload applies settings without normally disconnecting existing clients.
Exercise
Which two permission layers must allow a user to write a file in the projects share?
Show answer
The Samba share configuration and the underlying Linux ownership and mode permissions must both allow the write.