Sub topic 2
SMB and the Samba daemons
This chapter assumes you can use the Linux command line, manage services with systemctl, and read basic file permissions. It explains what the SMB protocol is and which Samba programs implement it. The next chapter covers the configuration file itself.
What SMB is
SMB (Server Message Block) is a client-server protocol for file and printer sharing. A client opens a connection to a server, authenticates, connects to a named share, and then sends requests to open, read, write, lock, and list files. Windows uses SMB natively, and macOS and Linux clients also support it. The older name CIFS refers to a specific dialect of the protocol, SMB1. People often say "CIFS" when they mean SMB in general, and the Linux kernel client is still called cifs.
Samba is the open-source implementation of SMB for Unix-like systems. It lets a Linux server act as a Windows-compatible file server. It also does more than serve files: it can resolve Windows account names, join a Windows domain, and act as a domain controller.
Protocol versions
SMB has several dialects. The dialect you allow affects both compatibility and security.
| Dialect | Introduced with | Notes |
|---|---|---|
| SMB1 (CIFS) | Windows NT and earlier | Obsolete and insecure. Avoid it. |
| SMB 2.0 / 2.1 | Windows Vista / 7 | Fewer round trips, better performance. |
| SMB 3.0 / 3.0.2 | Windows 8 / 8.1 | Adds optional encryption. |
| SMB 3.1.1 | Windows 10 | Adds pre-authentication integrity and AES-based encryption. |
Client and server negotiate the highest dialect they both support. Since Samba 4.11, the server's default minimum is SMB2, so SMB1 clients are refused unless you re-enable it. The example configuration in this tutorial sets server min protocol = SMB2 explicitly, so the intent stays visible even if defaults change.
The Samba daemons
A daemon is a background process. Samba is split into several of them, and which ones you run depends on the server's role.
| Daemon | Purpose | Needed for |
|---|---|---|
| `smbd` | Serves files and printers, authenticates users, enforces permissions | Every file server |
| `nmbd` | NetBIOS name service: name registration and browse lists | Legacy name resolution only |
| `winbindd` | Maps domain users and groups to local UIDs and GIDs | Domain members |
| `samba` | Active Directory domain controller | AD DC role only |
smbd
smbd is the daemon you will work with most. It listens on TCP port 445 (SMB directly over TCP). It also listens on TCP 139, which is the older SMB-over-NetBIOS transport. When a client connects, smbd forks a child process to serve that client. One crashed or stuck session therefore does not affect other users, and each child runs under the identity of the authenticated user. You can see these processes in ps, and smbstatus summarizes them.
Because smbd runs as root and switches to the authenticated user for file access, a Samba user ultimately needs a matching Unix identity. File access is then checked against normal Unix permissions, plus any restrictions from the share definition. This is why group ownership and the setgid bit matter later in the tutorial.
nmbd
nmbd handles NetBIOS name service on UDP ports 137 and 138. In the past it let clients find servers by name through broadcasts. On modern networks, DNS does this job. You can address the server by its DNS name (//fileserver/projects) without nmbd. Run it only if you have older clients or rely on network browsing. If you do not need it, leaving it stopped means fewer open ports.
winbindd
winbindd connects Samba to a Windows domain. It translates domain accounts such as EXAMPLE\alice into UIDs and GIDs that Linux understands. A standalone file server, like the one we build in this tutorial, does not need it. A later chapter covers it.
The samba binary
The samba program is a different mode of operation. It runs an Active Directory domain controller with its own LDAP, Kerberos, and DNS components, and it replaces smbd, nmbd, and winbindd as separate services. Do not enable it on a plain file server.
Installing and naming the services
Package and unit names differ between distribution families.
| Item | Debian / Ubuntu | RHEL family |
|---|---|---|
| Server package | `samba` | `samba` |
| Winbind package | `winbind` | `samba-winbind` |
| Client tools | `smbclient` | `samba-client` |
| File service unit | `smbd` | `smb` |
| NetBIOS unit | `nmbd` | `nmb` |
| Winbind unit | `winbind` | `winbind` |
Install and start the file service on Debian or Ubuntu:
sudo apt install samba smbclient
sudo systemctl enable --now smbd
systemctl status smbd --no-pagerOn a Red Hat-family system, use the matching names:
sudo dnf install samba samba-client
sudo systemctl enable --now smb
systemctl status smb --no-pagerA unit named smbd on one system and smb on another is a common reason for "Unit not found" errors. Check which one your distribution uses before you copy commands.
Seeing what is running
After the service starts, confirm that it is listening and look at the running daemons:
sudo ss -tlnp | grep -E ':(139|445)\b'
ps -C smbd,nmbd -o pid,ppid,user,cmd
sudo smbstatusThe ss command should show smbd bound to ports 139 and 445. In ps, the parent smbd process runs as root, and when clients connect you will see additional smbd children with that parent's PID. With no clients, smbstatus shows empty tables for sessions, shares, and locked files. It is a useful first diagnostic and returns later in the troubleshooting chapter.
How a connection works
The diagram shows the path of a typical request to a standalone server.
The steps are:
- The client opens TCP 445 and negotiates a dialect.
- The client authenticates. On a standalone server,
smbdchecks the credentials against Samba's own password database. - The client requests a share by name, and
smbdfinds the matching section insmb.conf. - For each file operation, the child process acts as the authenticated user, so Unix permissions apply.
Common mistakes
- Assuming a Unix password works for Samba. Samba stores its own password hash, so a user must be added to it separately. The next chapters cover this.
- Opening only port 445 and wondering why older clients fail. They may need 139, and name browsing needs UDP 137 and 138.
- Starting
nmbdandwinbinddon a simple server "just in case". Each additional daemon is more attack surface and more logs to read. - Re-enabling SMB1 to fix a legacy device. Isolate or replace the device instead.
Exercise
A new Debian file server runs only smbd. A Linux client can mount //fileserver/projects by DNS name, but a very old Windows device cannot find the server in its network browser. Which daemon is most likely missing, and why does the Linux client not need it?
Show answer
nmbd is missing. It provides NetBIOS name registration and browse lists on UDP 137 and 138, which the old device relies on. The Linux client resolves fileserver through DNS and connects straight to smbd on TCP 445, so it never uses NetBIOS name service.
Exercise
You follow a tutorial that says sudo systemctl restart smbd, but on your Rocky Linux server you get "Unit smbd.service not found". What is the fix?
Show answer
Red Hat-family systems name the file service unit smb, so run sudo systemctl restart smb.