21.4. Providing SMB Shares with Samba

Samba gives the same directories a second, differently-trusted door: clients authenticate by user account rather than by source address, and the server - not the client - decides which Unix identity each session acts as. Debian's samba package runs the classic standalone server: smbd handles file service on TCP 445, and nmbd provides legacy name browsing that modern clients no longer need but that costs nothing to run. Domain controllers, domain members, and winbind integration are a different deployment shape entirely - the server role distinction matters - and Chapter 35 takes up that path. This section builds the standalone server.

21.4.1. Standalone Server Configuration and Samba Accounts

On filesrv, as john, install the server (apt prints its plan and asks for confirmation, as it did for the NFS packages):

$ sudo apt install samba samba-common-bin

The package installs the smbd and nmbd service units. Debian's units carry an is-configured start condition - visible in the status output below - that keeps smbd from serving until a real configuration exists, which is why writing the configuration file comes next.

Samba's entire policy lives in one file. The complete contents of /etc/samba/smb.conf on filesrv:

[global]
   workgroup = WORKGROUP
   server string = Debian 13 file server
   server role = standalone server
   security = user
   passdb backend = tdbsam
   map to guest = never
   usershare allow guests = no
   server min protocol = SMB2_10
   client min protocol = SMB2_10
   server signing = mandatory
   smb encrypt = required
   hosts allow = 192.168.230. 10.21.0.
   log file = /var/log/samba/log.%m
   max log size = 1000
   logging = file
   obey pam restrictions = yes
   unix password sync = no
   pam password change = yes
   idmap config * : backend = tdb

[team]
   comment = Team collaboration
   path = /srv/nfs/team
   browseable = yes
   read only = no
   valid users = @team
   force group = team
   create mask = 0660
   directory mask = 2770
   inherit permissions = yes
   store dos attributes = yes
   map archive = no
   map hidden = no
   map system = no

[private]
   comment = Private home share
   path = /srv/nfs/private
   browseable = no
   read only = no
   valid users = john
   create mask = 0600
   directory mask = 0700
   store dos attributes = yes
   map archive = no
   map hidden = no
   map system = no

[public]
   comment = Read-only shared files
   path = /srv/nfs/public
   browseable = yes
   read only = yes
   valid users = @team
   guest ok = no

The globals encode this server's security stance. security = user with map to guest = never means every session authenticates against the local passdb and anonymous access is refused outright. The protocol floors - server min protocol = SMB2_10 - retire SMB1, which modern clients do not need and which Samba has disabled by default since the 4.11 series; stating it keeps the floor from drifting back if the file is edited. server signing = mandatory and smb encrypt = required demand signed, encrypted SMB3 sessions. hosts allow is a service-layer trust boundary: only the LAN and the tunnel network may connect at all, whatever an account's password might be.

Validate the configuration before trusting it:

$ sudo testparm -s
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed by GnuTLS (e.g. NTLM as a compatibility fallback)

Server role: ROLE_STANDALONE

# Global parameters
[global]
    client min protocol = SMB2
    log file = /var/log/samba/log.%m
    logging = file
    max log size = 1000
    obey pam restrictions = Yes
    pam password change = Yes
    security = USER
    server min protocol = SMB2
    server role = standalone server
    server signing = required
    server string = Debian 13 file server
    idmap config * : backend = tdb
    hosts allow = 192.168.230. 10.21.0.


[team]
    comment = Team collaboration
    create mask = 0660
    directory mask = 02770
    force group = team
    inherit permissions = Yes
    map archive = No
    path = /srv/nfs/team
    read only = No
    valid users = @team


[private]
    browseable = No
    comment = Private home share
    create mask = 0600
    directory mask = 0700
    map archive = No
    path = /srv/nfs/private
    read only = No
    valid users = john


[public]
    comment = Read-only shared files
    path = /srv/nfs/public
    valid users = @team
Option Description
-s Skip the "press Enter" pause and print the processed configuration
-v Include every parameter with its default value, not only those set explicitly
filepath Optional argument: validate that file instead of /etc/samba/smb.conf

Read the summary with care: it shows only non-default parameters, so an option absent from the dump is at its default, not missing. The GnuTLS "weak crypto" note records that NTLM remains available as a compatibility fallback - acceptable on a LAN with mandatory signing, and worth knowing it is there. Two normalizations appear: SMB2_10 prints as SMB2 (the summary reports the protocol family floor), and mandatory prints as required. Encryption is configured in the file (smb encrypt = required) but does not appear in the short summary - testparm -sv shows it, and the live sessions in Section 21.4.4 prove it. The failure mode is worth one deliberate look; save this throwaway two-line file as /tmp/smb-bad.conf:

[global]
   server min protocol = SMB9
$ sudo testparm -s /tmp/smb-bad.conf
Load smb config files from /tmp/smb-bad.conf
WARNING: Ignoring invalid value 'SMB9' for parameter 'server min protocol'
Error loading services.

testparm names the parameter and the rejected value, and the nonzero exit status makes it usable as a gate before any restart - a restart with this file would leave smbd unable to load its configuration. Validate first, restart second (the restart itself prints nothing):

$ sudo systemctl restart smbd nmbd
$ sudo systemctl status smbd --no-pager --lines=4
● smbd.service - Samba SMB Daemon
     Loaded: loaded (/usr/lib/systemd/system/smbd.service; enabled; preset: enabled)
     Active: active (running) since Sun 2026-11-22 03:59:10 UTC; 2s ago
 Invocation: c93e53c510b44d71852b3d15af0ceed9
       Docs: man:smbd(8)
             man:samba(7)
             man:smb.conf(5)
    Process: 29629 ExecCondition=/usr/share/samba/is-configured smb (code=exited, status=0/SUCCESS)
    Process: 29632 ExecStartPre=/usr/share/samba/update-apparmor-samba-profile (code=exited, status=0/SUCCESS)
   Main PID: 29642 (smbd)
     Status: "smbd: ready to serve connections..."
      Tasks: 3 (limit: 1108)
     Memory: 7.9M (peak: 8.1M)
        CPU: 174ms
     CGroup: /system.slice/smbd.service
             ├─29642 /usr/sbin/smbd --foreground --no-process-group
             ├─29645 "smbd: notifyd" .
             └─29646 "smbd: cleanupd "

Nov 22 03:59:10 filesrv systemd[1]: Starting smbd.service - Samba SMB Daemon...
Nov 22 03:59:10 filesrv systemd[1]: Started smbd.service - Samba SMB Daemon.

active (running) with a real daemon PID this time - smbd is a long-running service, unlike the oneshot NFS starter. It is listening on TCP 445; the firewall from Section 21.2.3 already admits the trusted networks to that port.

Now the accounts. Samba keeps its own password database - tdbsam, a local TDB file - and an SMB account exists only when an administrator creates one for a user who already exists as a Unix account. On filesrv, in the root shell ($ sudo -i from john's shell):

# printf "handbook\nhandbook\n" | smbpasswd -s -a john
Added user john.
# printf "handbook\nhandbook\n" | smbpasswd -s -a alice
Added user alice.

The -a flag adds the Unix user to the passdb; -s reads the password from standard input instead of a terminal prompt, so the pipeline feeds the password twice (once as the entry, once as the confirmation). Typed interactively - smbpasswd -a john from the same root shell - the command prompts for the new password twice and echoes nothing, which is the form to prefer when a terminal is available. Note the deliberate separation from Section 21.1.2: this password is only the SMB credential; changing it does not change john's login password, because unix password sync = no.

Verify the passdb contents - on filesrv, as john:

$ sudo pdbedit -L
john:2100:
alice:2101:
Option Description
-L List passdb accounts (name:UID:)
-a user Add a Unix user to the passdb, prompting for the SMB password
-x user Remove the SMB account
-u user Operate on a single named user

The listing shows each SMB account bound to its Unix UID - the mapping that turns an authenticated session into a filesystem identity.

21.4.2. Private Shares and Controlled Group Collaboration

The three shares apply three different policies to the same access questions - who may connect, who may see the share exists, and what new files look like:

Share Visible in browse Who may connect New files
team yes members of team (@team) mode 0660, group forced to team
private no john alone mode 0600
public yes members of team read-only; no creation

valid users is the connect gate: @team names a Unix group (the @ prefix), and membership is checked after authentication. The masks take effect at file creation; force group = team makes the collaboration group stick regardless of the creator's primary group, playing the same role as the setgid bit on the NFS side. browseable = no removes private from share listings without blocking direct connections - the name must be known, which is obscurity as an adjunct to the valid users gate, never a substitute for it.

Check the policy from a real client session. On client1, as john, list what the server offers:

$ smbclient -L //files.lab.example -U john%handbook -m SMB3

    Sharename       Type      Comment
    ---------       ----      -------
    team            Disk      Team collaboration
    public          Disk      Read-only shared files
    IPC$            IPC       IPC Service (Debian 13 file server)
SMB1 disabled -- no workgroup available

The -U john%handbook form puts the account and password on the command line - convenient for a disposable lab, visible in shell history anywhere else; the interactive alternative is -U john, which prompts for the password without echoing it. The listing shows exactly the design: team and public visible, private absent, IPC$ the named-pipe share every SMB server exposes, and the final line confirming SMB1 never even negotiated.

Connect to the team share and look inside:

$ smbclient //files.lab.example/team -U john%handbook -m SMB3 -c "ls"
  .                                   D        0  Sun Nov 22 03:57:01 2026
  ..                                  D        0  Sun Nov 22 03:57:01 2026
  john-nfs.txt                        N       19  Sun Nov 22 03:57:01 2026

        61440 blocks of size 1024. 61424 blocks available

-c "ls" runs one command in the share and exits. The same tree the NFS client mounted as /mnt/team is here through SMB - the same file from Section 21.3.1, same size, and the trailing line reports the share's free space the way a Windows client would see it. Alice is a member of team, so her account opens the same share but must fail on the private one - on client1, as john, using alice's credentials:

$ smbclient //files.lab.example/private -U alice%handbook -c "ls"
tree connect failed: NT_STATUS_ACCESS_DENIED

Alice authenticated successfully - a wrong password would have produced NT_STATUS_LOGON_FAILURE - and the server then refused the share connection at the valid users gate. Authentication and authorization are separate refusals with separate statuses, which makes this exact distinction the first diagnostic split when a user cannot reach a share.

21.4.3. Mapping SMB Access to Unix Permissions and ACLs

Everything an SMB client does lands on the ext4 directory as ordinary Unix metadata, and Samba's job is to translate faithfully in both directions. Watch the full round trip, starting with the default ACL on the team directory - on filesrv, as john:

$ sudo getfacl -p /srv/nfs/team
# file: /srv/nfs/team
# owner: john
# group: team
# flags: -s-
user::rwx
group::rwx
other::---
default:user::rwx
default:user:alice:rwx
default:group::rwx
default:mask::rwx
default:other::---

The flags: -s- line records the setgid bit, and the default: block is the inheritance rule set in Section 21.2.1 - files created here get alice's named entry and the team group entry automatically. (-p keeps absolute path names in the # file: header; without it getfacl strips the leading slash.)

Create a file through SMB - on client1, as john, first put a real file in the workspace and upload it:

$ printf "team file from john\n" > ~/debian-handbook/network-files/team-john.txt

The redirection writes the file; nothing prints. Upload it to the share:

$ smbclient //files.lab.example/team -U john%handbook -c "put /home/john/debian-handbook/network-files/team-john.txt team-john.txt"
putting file /home/john/debian-handbook/network-files/team-john.txt as \team-john.txt (9.8 kb/s) (average 9.8 kb/s)

put copies the workspace file to the share as team-john.txt. (The path is written absolute because it sits inside a quoted argument, where the shell does not expand ~.) Now look at what the server stored - on filesrv, in the root shell:

# getfacl -p /srv/nfs/team/team-john.txt
# file: /srv/nfs/team/team-john.txt
# owner: john
# group: team
user::rw-
user:alice:rwx  #effective:rw-
group::rwx  #effective:rw-
mask::rw-
other::---

The upload arrived as Unix metadata doing exactly what the layers predict: owner john, group forced to team, and the default ACL's entries inherited onto the new file. The #effective: annotations are the POSIX ACL mask at work - the create mask = 0660 share rule limited the effective rights to rw-, so the rwx entries are masked down for actual permission checks. The two systems (Samba masks, POSIX ACLs) composed rather than conflicted.

The transfer round trip back through a second user proves the share works for the whole group - on client1, as john, using alice's credentials to fetch the file john uploaded:

$ smbclient //files.lab.example/team -U alice%handbook -c "get team-john.txt /home/john/debian-handbook/network-files/team-john-alice.txt"
getting file \team-john.txt of size 20 as /home/john/debian-handbook/network-files/team-john-alice.txt (9.8 KiloBytes/sec) (average 9.8 KiloBytes/sec)
$ cmp ~/debian-handbook/network-files/team-john.txt ~/debian-handbook/network-files/team-john-alice.txt && echo identical
identical

cmp compares the two files byte for byte and prints nothing when they match; && runs echo identical only because cmp succeeded, so the single word is the proof. The downloaded copy landed with the workspace's normal ownership:

$ stat -c '%u %g %a %n' ~/debian-handbook/network-files/team-john-alice.txt
2100 2100 644 /home/john/debian-handbook/network-files/team-john-alice.txt

The remaining translation detail is Windows attributes. SMB clients expect to store DOS-style metadata - archive, hidden, system bits - and Samba historically mapped those bits onto Unix permission bits that were never meant for them (the archive bit onto the owner's execute bit, producing mode 760 files). The modern, honest mechanism is store dos attributes = yes: attributes live in an extended attribute named user.DOSATTRIB, and map archive = no (with hidden and system likewise unmapped) keeps the permission bits clean. The share configuration uses exactly that pair, and the file shows both results - on filesrv, in the root shell:

# getfattr -d -m - /srv/nfs/team/team-john.txt
getfattr: Removing leading '/' from absolute path names
# file: srv/nfs/team/team-john.txt
system.posix_acl_access=0sAgAAAAEABgD/////AgAHADUIAAAEAAcA/////xAABgD/////IAAAAP////8=
user.DOSATTRIB=0sAAAFAAUAAAARAAAAIAAAAPd7V+I1et0B

getfattr -d -m - dumps every extended attribute with a name matching any namespace. The first line is bookkeeping, not an error: given an absolute path, getfattr reports that it displays the path without its leading slash - which is also why the # file: header reads srv/nfs/.... Two attributes are present: the POSIX ACL stored by the filesystem (system.posix_acl_access) and the DOS attributes stored by Samba (user.DOSATTRIB) - and the file's mode stayed 660 because nothing hijacked a permission bit. The same mechanism carries the attribute to NFS clients as a user extended attribute, which Section 21.6.2 shows from the client side.

One alternative completes the picture. Samba can also present genuine Windows ACLs backed by an acl_xattr VFS module, storing a security.NTACL blob and letting Windows administrators manage permissions from their own security dialog. That is the right choice when Windows clients actually manage the share's permissions; it is documented in smb.conf(5) under the module's section, and it was not the model exercised here. This chapter's shares use Unix modes and POSIX ACLs as the single source of truth, with both NFS and SMB translating into it - one policy, two doors.

21.4.4. Validating Configuration and Inspecting Active Connections

A file server earns trust through what it can show about itself. Samba's inspection tool is smbstatus, which reads the live connection table. The captures below were taken with the team and private CIFS mounts from Section 21.5.2 active on client1 - run that section first, then on filesrv, as john:

$ sudo smbstatus -b

Samba version 4.22.11-Debian-4.22.11+dfsg-0+deb13u1
PID     Username     Group        Machine                                   Protocol Version  Encryption           Signing              
----------------------------------------------------------------------------------------------------------------------------------------
29840   john         john         192.168.230.20 (ipv4:192.168.230.20:47360) SMB3_11           AES-128-GCM          AES-128-CMAC         
Option Description
-b Brief: one line per authenticated client connection
-S Shares: one line per share connection
-L Locks: open files and byte-range locks held by clients
-p Process list: smbd child processes with connected users

The single line carries the whole security story from Section 21.4.1's globals: the client negotiated SMB 3.1.1 (SMB3_11), the session is encrypted with AES-128-GCM, and every message is signed with AES-128-CMAC - the seal mount option in Section 21.5.2 is what requested the encryption. The per-share view adds which trees that session has open:

$ sudo smbstatus -S

Service      pid     Machine       Connected at                     Encryption   Signing     
---------------------------------------------------------------------------------------------
team         29840   192.168.230.20 Sun Nov 22 03:59:48 2026 UTC     AES-128-GCM  AES-128-CMAC
IPC$         29840   192.168.230.20 Sun Nov 22 03:59:48 2026 UTC     AES-128-GCM  AES-128-CMAC
private      29840   192.168.230.20 Sun Nov 22 03:59:58 2026 UTC     AES-128-GCM  AES-128-CMAC

One client machine, three tree connections, all encrypted and signed. IPC$ appears because the mount sequence used the named-pipe share for negotiation, not because anyone browsed it.

When a connection is refused, the log records the reason. Samba writes per-machine logs using the log file = /var/log/samba/log.%m pattern plus a general log.smbd; a client rejected by hosts allow produces a Denied connection from <address> line in that general log - Section 21.7.3 refuses a client on purpose and reads the matching entry there. Between smbstatus for the live state, testparm for the intended state, and the logs for the refused state, the server can answer every "who is doing what" question an incident or a user complaint raises.