21.5. Using and Troubleshooting SMB Clients
The server sections already used smbclient for spot checks; this
section treats the client side properly - the interactive tool, the
kernel CIFS mount with protected credentials, the desktop path, and
the negotiation and permission failures that dominate real support
requests. The packages are already installed on client1 from
Section 21.3.1.
21.5.1. Browsing and Testing Shares with smbclient
smbclient is a command-line SMB client in the shape of an FTP
session: it connects, authenticates, and then takes commands until you
leave. The options used across this chapter:
| Option | Description |
|---|---|
-L //server |
List the server's shares, then exit (no share connection) |
-U user |
Authenticate as user; user%password puts the password on the command line, -U user alone prompts for it |
-m PROTO |
Offer at most protocol level PROTO (SMB3, SMB2, ...) |
-c "commands" |
Run the quoted client commands, then exit |
-p port |
Connect on a nonstandard TCP port |
--option="k=v" |
Override one client-side configuration value for this invocation |
The shares listing (smbclient -L) and the one-shot ls ran in
Section 21.4.2; the everyday form is the interactive session. On
client1, as john, smbclient //files.lab.example/team -U john%handbook
-m SMB3 authenticates and opens a prompt at the share's root,
displayed as smb: \>. It is a command shell over the share: ls,
get file and put file for transfers, cd and lcd to move on
the server and in the local directory, mkdir, rm, and exit to
leave - the same command vocabulary the -c form accepts. The
interactive session is the right tool for exploring an unfamiliar
share; the one-shot -c form shown throughout this chapter is the
same session with commands supplied up front, which makes it the
building block for scripts - the put of Section 21.4.3 is exactly
that. For unattended use, -A credentials-file reads the same
username/password/domain file format as mount.cifs, so a script needs
no password on any command line.
smbclient is also the fastest diagnostic for a reported access
problem, because its errors are the protocol's own statuses. A wrong
password fails at session setup:
$ smbclient -L //files.lab.example -U john%wrong
session setup failed: NT_STATUS_LOGON_FAILURE
NT_STATUS_LOGON_FAILURE means authentication itself failed - the
account or the password is wrong. A share-level refusal, like alice's
attempt on private in Section 21.4.2, is NT_STATUS_ACCESS_DENIED
at tree connect - the account works, the policy does not. That
one-status difference localizes the failing layer before any server
log is opened.
21.5.2. Persistent CIFS Mounts and Protected Credentials
A kernel CIFS mount makes an SMB share behave like a local filesystem
for every program, the same way NFS does - but the mount must
authenticate, and a password on a mount command line or in
/etc/fstab would be world-readable in process lists and files. The
protected answer is a credentials file owned by the invoking user. On
client1, as john:
$ umask 077
umask 077 strips group and other permissions from files this shell
creates - it affects new files only, for this session. Write the
credentials file:
$ printf "username=john\npassword=handbook\ndomain=WORKGROUP\n" > ~/debian-handbook/network-files/.smbcredentials
The redirection writes the three lines; nothing prints. Verify what was created:
$ stat -c "%a %U:%G %n" ~/debian-handbook/network-files/.smbcredentials
600 john:john /home/john/debian-handbook/network-files/.smbcredentials
Mode 600, owned by john - the password file is private. The domain
line matters for workgroup servers that report a non-default domain
during negotiation; with WORKGROUP it is harmless to include. Create
the mount points - on client1, in the root shell ($ sudo -i from
john's shell):
# mkdir -p /mnt/smbteam /mnt/smbprivate /mnt/smbsmb2
The command is silent. Back in john's shell (exit), mount the team
share:
$ sudo mount -t cifs //files.lab.example/team /mnt/smbteam -o credentials=/home/john/debian-handbook/network-files/.smbcredentials,uid=2100,gid=2105,vers=3.1.1,seal,file_mode=0660,dir_mode=02770
The mount options carry the whole client-side policy:
| Option | Description |
|---|---|
credentials=path |
Read username, password, and domain from a protected file instead of the command line |
uid=, gid= |
Present every file as owned by these IDs on the client (needed because the mount is not POSIX-unix aware) |
vers=3.1.1 |
Require SMB 3.1.1 (SMB3 with encryption support) rather than negotiating down |
seal |
Require encryption for this session |
file_mode=, dir_mode= |
Client-side mode presentation for files and directories |
_netdev, nofail, x-systemd.* |
The same boot-safety options NFS used in Section 21.3.2 |
A silent command means success. Check what the kernel negotiated:
$ findmnt -no TARGET,SOURCE,FSTYPE,OPTIONS /mnt/smbteam
/mnt/smbteam //files.lab.example/team cifs rw,relatime,vers=3.1.1,cache=strict,upcall_target=app,username=john,domain=WORKGROUP,uid=2100,forceuid,gid=2105,forcegid,addr=192.168.230.10,file_mode=0660,dir_mode=02770,seal,soft,nounix,serverino,mapposix,reparse=nfs,rsize=4194304,wsize=4194304,bsize=1048576,echo_interval=60,actimeo=1,closetimeo=1
vers=3.1.1 and seal appear as requested, and one default deserves
attention: soft. The CIFS client fails over after bounded retries
where NFS's default waits indefinitely - the two protocols chose
opposite defaults for the same question, and a site standardizing on
one behavior should set it explicitly on the other. The uid=2100,
forceuid pair means the client presents the share's files as john's
regardless of the server-side owner, which is the correct
presentation for a single-user mount of a shared directory (the
server's own permission checks still govern what the session may do).
Write through the mount and compare both ends - first the write, whose output is redirected into the file:
$ printf "made over cifs\n" > /mnt/smbteam/cifs-john.txt
$ stat -c "%u %g %a %n" /mnt/smbteam/cifs-john.txt
2100 2105 660 /mnt/smbteam/cifs-john.txt
That is the client's view. On filesrv, in the root shell:
# stat -c '%u %g %a %n' /srv/nfs/team/cifs-john.txt
2100 2105 660 /srv/nfs/team/cifs-john.txt
Owner 2100, group 2105, mode 660 - on both sides, matching the NFS
result from Section 21.3.1 exactly. The force group and create
mask from the share definition did on the SMB path what the setgid
bit and default ACL did on the NFS path. One file, two protocols, one
coherent permission state.
The private share demonstrates the per-share override:
$ sudo mount -t cifs //files.lab.example/private /mnt/smbprivate -o credentials=/home/john/debian-handbook/network-files/.smbcredentials,uid=2100,gid=2100,vers=3.1.1,seal,file_mode=0600,dir_mode=0700
Silent again, as a successful CIFS mount always is:
$ ls -la /mnt/smbprivate
total 4
drwx------ 2 john john 0 Nov 22 03:54 .
drwxr-xr-x 21 root root 4096 Nov 22 02:29 ..
The client sees the private tree as john:john 0700 - the file_mode
and dir_mode options presenting the share's privacy consistently.
Unmount both test mounts before making them persistent - as john:
$ sudo umount /mnt/smbteam /mnt/smbprivate
The unmounts print nothing. For persistence, the same fstab pattern as NFS: add this line to
/etc/fstab on client1:
//files.lab.example/team /mnt/smbteam cifs credentials=/home/john/debian-handbook/network-files/.smbcredentials,uid=2100,gid=2105,vers=3.1.1,seal,file_mode=0660,dir_mode=02770,_netdev,nofail,x-systemd.automount,x-systemd.idle-timeout=60 0 0
The credentials path is absolute and inside john's home - readable by root at mount time, which is exactly who needs it and exactly who the mode-600 file admits. Reload systemd and start the automount unit - on client1, in the root shell (both commands are silent):
# systemctl daemon-reload
# systemctl start mnt-smbteam.automount
Back in john's shell, trigger and verify:
$ ls /mnt/smbteam >/dev/null; findmnt -no TARGET,SOURCE,FSTYPE /mnt/smbteam
/mnt/smbteam systemd-1 autofs
/mnt/smbteam //files.lab.example/team cifs
The same two-layer autofs result as the NFS case: the share mounts on
access, unmounts after a minute idle, and costs boot nothing. The
password never appears in /etc/fstab, in a process listing, or in
shell history.
21.5.3. Desktop Access and User-Specific Mounts
Workstations with a desktop do not need root, fstab entries, or credential files for SMB access; the desktop's virtual filesystem layer handles all of it per user. On GNOME, open Files (the file manager), press Ctrl+L to focus the location bar, and enter:
smb://files.lab.example/team
The first connection prompts for credentials - username, domain, and
password - and offers to remember them in the login keyring, after
which the share appears in the sidebar under Network for future
sessions. The backend is GVfs, the desktop's user-space virtual
filesystem: its SMB support ships in Debian's gvfs-backends
package, and the resulting mount lives under the user's runtime
directory, something like /run/user/2100/gvfs/smb-share:server=files.lab.example,share=team
- visible and usable from the file manager and from applications, but
owned by that session's user, with that user's credentials, and gone
when the session ends.
That session scope is the design difference from Section 21.5.2's
fstab mounts: nothing persists across reboots, no root privilege is
involved, each user sees only shares their own account can open, and
two users on one workstation never see each other's mounts. A user
who wants a GVfs mount without opening the file manager can ask for
the same thing from a terminal with gio mount
smb://files.lab.example/team, which authenticates and creates the
same per-user mount; unmounting is gio mount -u with the mount's
location or the file manager's eject control.
The shares themselves do not change for desktop clients: the
authentication, valid users, masks, and encryption requirements of
Section 21.4 apply identically, because the GVfs client negotiates
the same SMB3 the kernel client does. What differs is only who owns
the credential and the mount - the user, not the system. Choose per
population: servers and shared workstations mount system-wide with
protected credentials files; personal desktops use the session mount
and the keyring.
21.5.4. Protocol Negotiation, Authentication, and Permission Failures
SMB client failures come in a small set of recognizable shapes, and the lab's server configuration - protocol floors, mandatory signing, required encryption - produces most of them deliberately. Collecting them in one place, with their causes:
An obsolete client attempts SMB1:
$ smbclient -L //files.lab.example -U john%handbook --option="client min protocol=NT1" -m NT1
Protocol negotiation to server files.lab.example (for a protocol between NT1 and NT1) failed: NT_STATUS_INVALID_NETWORK_RESPONSE
smbXcli_negprot_smb1_done: No compatible protocol selected by server.
The --option override forced the client to offer only NT1 (SMB1),
and the server's server min protocol = SMB2_10 floor ended
negotiation before any authentication - the second line is the
client's plain-language summary. A tool or appliance that produces
this error is speaking a protocol retired for security reasons; the
fix is updating it, never lowering the floor.
A modern-but-unencrypted dialect fails differently. Request SMB2 explicitly:
$ smbclient //files.lab.example/team -U john%handbook -m SMB2 -c "ls"
session setup failed: NT_STATUS_ACCESS_DENIED
SMB2 negotiated - the protocol floor allows it - but SMB2 has no
session encryption, and smb encrypt = required refuses to continue.
The status is ACCESS_DENIED rather than a negotiation error because
the refusal happens at session setup, after the dialect was chosen.
The kernel client shows the same policy from the mount side:
$ sudo mount -t cifs //files.lab.example/team /mnt/smbsmb2 -o credentials=/home/john/debian-handbook/network-files/.smbcredentials,uid=2100,gid=2105,vers=2.1
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)
The kernel's translation of the same refusal: mount error(13) is
EACCES, and the message correctly points at dmesg, where the CIFS
module logs the server's refusal. Every working path in this chapter
therefore pins vers=3.1.1 with seal - a client allowed to negotiate
down would either fail late or, worse, succeed unencrypted against a
laxer server.
Authentication and authorization failures were captured in their natural places and summarize cleanly:
| Symptom | Layer refusing | Evidence |
|---|---|---|
NT_STATUS_LOGON_FAILURE at session setup |
passdb: account or password wrong | Section 21.5.1 |
NT_STATUS_ACCESS_DENIED at tree connect |
share valid users |
Section 21.4.2 |
NT_STATUS_ACCESS_DENIED at session setup with SMB2 |
smb encrypt = required |
this section |
| Negotiation failure with NT1 | server min protocol floor |
this section |
| Connection never completes, no client error | hosts allow or the firewall |
Section 21.7.3 |
The last row is the deceptive one: a client refused by Samba's
hosts allow gets no useful status at all, and a client dropped by
nftables sees silence. The server-side views - smbstatus for who is
connected, the Samba logs for who was refused (Section 21.4.4), the
firewall counters of Chapter 18 - are what
localize a silent failure. Permission failures on existing
connections have one more classic cause worth naming: the Unix layer.
A session authenticated as john that cannot read a file owned
root:root 0600 is being refused by the filesystem, exactly as a local
process would be - getfacl on the server settles it in seconds.