Sub topic 6
Checking your Samba setup
This chapter assumes you have a working smb.conf with at least one share, a Samba user created with smbpasswd -a, and a shared directory with the right Unix permissions. It also assumes you are comfortable with systemctl and reading log output. Here you will learn to check a Samba server in layers, so that when something fails you know which layer broke.
The verification ladder
A Samba share can fail at several independent points. Checking them in order saves time, because a failure at one step makes every later step meaningless.
testparmchecks the configuration file.systemctlandsscheck that the daemon runs and listens.smbclient -Lchecks that the server offers the share.smbclient //server/sharechecks authentication and permissions.smbstatusshows live sessions.
Step 1: Validate the configuration with testparm
testparm parses smb.conf and reports syntax errors and suspicious settings. Run it before every restart.
sudo testparmA clean run prints lines like these, then waits for you to press Enter to show the effective configuration:
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Server role: ROLE_STANDALONEPress Enter, or add -s to skip the prompt and print the result directly:
sudo testparm -sThe output of testparm -s is useful for two reasons.
- It shows the effective configuration after defaults are applied. Settings you did not write, such as
security = USER, appear here. - It shows only parameters that differ from the defaults, so a typo in a parameter name stands out.
testparm warns about unknown parameters. For example, a misspelled valid user = @staff (missing the final s) produces:
Unknown parameter encountered: "valid user"
Ignoring unknown parameter "valid user"This matters because Samba ignores the bad line. The share then loads without the restriction you intended. If you ignore a warning like this, the share can end up open to more people than you meant.
You can also check a single parameter or section:
sudo testparm -s --section-name=projects
sudo testparm -s --parameter-name="server min protocol"Note that testparm checks syntax and some consistency, such as whether the path directory exists. It does not check that the staff group exists or that the Unix permissions allow writing. Later steps cover those checks.
Step 2: Confirm the service is running and listening
After testparm passes, restart the service and check its state. The unit is smbd on Debian-family systems and smb on Red Hat-family systems.
sudo systemctl restart smbd
systemctl status smbd --no-pager
sudo ss -tlnp | grep smbdThe ss command should show smbd listening on TCP port 445. Port 139 appears only if NetBIOS over TCP is enabled in your configuration.
LISTEN 0 50 0.0.0.0:445 0.0.0.0:* users:(("smbd",pid=1234,fd=30))If nothing listens on 445, read the journal for the reason:
sudo journalctl -u smbd -n 50 --no-pagerStep 3: List shares with smbclient
smbclient is a command-line SMB client from the Samba package set (on some distributions it is a separate smbclient package). Use it first from the server itself, because that rules out the network and the firewall.
smbclient -L localhost -U aliceEnter alice's Samba password when prompted. The output has a section for shares:
Sharename Type Comment
--------- ---- -------
projects Disk
IPC$ IPC IPC Service (Samba Server)IPC$ is a built-in share used for the protocol's own management calls. It always appears. Your projects share should appear next to it.
A few results to recognize:
| Result | Likely cause |
|---|---|
| `NT_STATUS_LOGON_FAILURE` | Wrong password, or the user has no Samba password. A Unix password is not used. |
| `NT_STATUS_CONNECTION_REFUSED` | `smbd` is not running or not listening. |
| `Connection to localhost failed` after a long wait | A firewall drops the traffic, or the host name is wrong. |
| Share missing from the list | The share has `browseable = no`, or the section failed to load. |
Setting browseable = no hides a share from the list but does not block access. You can still connect to it if you know its name. Do not treat it as a security measure.
Then repeat the test from another machine, using the server's name or address instead of localhost:
smbclient -L //fileserver -U aliceIf localhost works and the remote test fails, the problem is in the network path: the firewall, routing, or name resolution. The firewall chapter covers the ports.
Step 4: Test a real file operation
Listing shares proves very little about permissions. Connect to the share itself and perform the operations your users need.
smbclient //localhost/projects -U aliceAt the smb: \> prompt, try each action:
smb: \> ls
smb: \> mkdir testdir
smb: \> put /etc/hostname hostname.txt
smb: \> ls
smb: \> del hostname.txt
smb: \> rmdir testdir
smb: \> exitYou can also run a single command non-interactively, which is handy in scripts:
smbclient //localhost/projects -U alice -c 'mkdir testdir; ls; rmdir testdir'In this chapter's example configuration, create mask = 0664 and force group = staff apply to new files. After a put, check the result on the server:
ls -l /srv/samba/projectsYou should see the file owned by alice with group staff and mode -rw-rw-r--. A directory should show drwxrwsr-x, where the s is the setgid bit from chmod 2775.
Two errors appear often at this step:
NT_STATUS_ACCESS_DENIEDon connect meansvalid usersexcludes the user, or the user is not in the group. Confirm withid alice. If you added alice tostaffafter starting a session, reconnect, because group membership is read at login.NT_STATUS_ACCESS_DENIEDonputormkdir, with the connection itself succeeding, usually means the Unix permissions on the directory do not allow writing. Samba cannot grant more access than the filesystem gives the mapped Unix user. Also check thatread only = nois set.
Step 5: Inspect live activity with smbstatus
smbstatus shows who is connected right now. Run it while a client has a share mounted.
sudo smbstatusThe output has three parts:
- Samba version and process list: each connected user, the client machine, the protocol version, and the signing and encryption state.
- Service connections: each share in use, with the process ID and the time of connection.
- Locked files: files currently open by clients, with the lock type.
Useful narrower forms:
sudo smbstatus --shares
sudo smbstatus --processes
sudo smbstatus --locksThe protocol column is a quick way to confirm your hardening settings. If you set server min protocol = SMB2 but see NT1 in the output, the setting is not being applied, and you should look for a second [global] section or an include file that overrides it.
Use smbstatus also to find out why a file cannot be saved or deleted: the locks view shows which user holds it open. Samba's own logs add detail when you need it.
Raising the log level
When the earlier steps do not explain a failure, increase the log level temporarily. The default is 0. Level 3 is a good working value for authentication and permission problems.
[global]
log level = 3
log file = /var/log/samba/log.%m
max log size = 5000The %m variable gives each client machine its own log file. After changing it, run testparm, reload the configuration with sudo smbcontrol all reload-config, reproduce the failure, then read the log for the client:
sudo tail -n 50 /var/log/samba/log.client1Lines containing NT_STATUS_ give the exact reason for the refusal. Return the level to 0 or 1 afterward. High log levels grow quickly and slow the server.
Common mistakes
- Skipping
testparmand discovering a syntax error only when the service fails to restart. - Testing only with
smbclient -L, then finding that writes fail. - Using a Unix password with
smbclient. Samba keeps its own password database, set withsmbpasswd. - Testing from the server and concluding the network path works. Always run one test from a separate machine.
- Leaving
log levelhigh after debugging.
Exercise
A user reports that they can see the projects share in smbclient -L but get NT_STATUS_ACCESS_DENIED when they run smbclient //fileserver/projects -U alice. testparm reports no problems. List three things you would check, in order, and the command you would use for each.
Show answer
First, check group membership with id alice, because valid users = @staff rejects users outside the staff group. Second, confirm the share is writable by the mapped user, using ls -ld /srv/samba/projects to check that the group has write permission and the setgid bit is set. Third, raise the log level to 3, reproduce the failure, and read /var/log/samba/log.<client> for the exact NT_STATUS_ reason. You can also run sudo smbstatus to confirm whether the session was established at all.
Exercise
You set server min protocol = SMB2 but want to confirm no client connects with the old SMB1 protocol. Which command shows the protocol each client uses?
Show answer
sudo smbstatus (or sudo smbstatus --processes) lists each connection with its protocol version. If a client shows NT1, the minimum protocol setting is not in effect for it, so check for overrides with testparm -s.