SkillPilotAI

SMB/CIFS: smbclient, mount.cifs, rpcclient, smbget, smbtree, net (Samba), smbutil, mount_smbfs (1/5)

smbclient is Samba's FTP-like client for Windows and Samba shares: it lists, downloads, uploads and backs up files over SMB on TCP 445. mount.cifs does a different job: it mounts a share on a Linux folder through the kernel cifs module. Part 1 covers smbclient in depth and the mount.cifs options.

155.1 Why is it used?

  • Access Windows file shares from Linux: copy files, script transfers, take tar backups of a share.
  • Troubleshoot SMB: which step fails (login vs share vs permission), which dialect and whether signing/encryption are on.
  • mount.cifs makes a share look like a normal folder so any app can use it.
  • Packages: Linux samba-client (apk, dnf) / smbclient (apt) and cifs-utils; macOS has smbutil and mount_smbfs; Windows uses net use / New-SmbMapping.

155.2 How it works: the SMB connection steps

  • Lab: smbclient on client 192.168.175.20, Samba 4.19.9 on filesrv 192.168.175.10 (TCP 445).
  • Negotiate picks the SMB dialect (here SMB3_11).
  • Session Setup checks the user and password (NTLMSSP or Kerberos).
  • Tree Connect opens the share (docs); then ls/get become SMB Read requests.
  • Each step has its own error, so the error tells you which step failed.
smbclient connection and where errors come from
  1. 1.Client 192.168.175.20 -> filesrv 192.168.175.10 TCP 445

  2. 2.NEGOTIATE -> dialect SMB3_11 (fails if versions do not overlap: NT_STATUS_NOT_SUPPORTED)

  3. 3.SESSION_SETUP asha -> wrong password: NT_STATUS_LOGON_FAILURE

  4. 4.TREE_CONNECT docs -> wrong share name: NT_STATUS_BAD_NETWORK_NAME

  5. 5.TREE_CONNECT hr as ravi -> not allowed: NT_STATUS_ACCESS_DENIED

  6. 6.Success: ls / get travel as SMB2 READ requests

Output
[global]   server min protocol = SMB2   smb3 unix extensions = yes[docs]   path = /srv/docs   valid users = asha ravi[backup]   valid users = asha[public]   read only = yes   guest ok = yes[hr]   valid users = asha[labprinter]   printable = yes

155.3 smbclient: target, port, protocol

  • -L lists shares; -g gives the same list script-friendly.
  • -I IP connects to an IP while using a NetBIOS name; -p 139 got connection refused (server only on 445).
  • -D dir starts in a folder; -c 'cmd; cmd' runs commands without a prompt.
  • -m sets the client's max protocol; --max-protocol=SMB2_02 failed because the server minimum is SMB2.1 (SMB2_10).
Terminal
S=192.168.175.10smbclient -L //$S -U asha%LabPass1smbclient -L $S -g -U asha%LabPass1smbclient //FILESRV/docs -I $S \  -U asha%LabPass1 -c pwdsmbclient //$S/docs -U asha%LabPass1 \  -D reports -c 'pwd; ls'smbclient //$S/docs -U asha%LabPass1 \  --max-protocol=SMB2_02 -c pwd
Output
$ smbclient //192.168.175.10/docs -U asha%LabPass1 -D reports -c 'pwd; ls'Current directory is \\192.168.175.10\docs\reports\  q3.txt                              N       18  Mon Nov  9 07:28:30 2026  q4.txt                              N        8  Mon Nov  9 07:28:30 2026  2025                                D        0  Mon Nov  9 07:28:30 2026$ smbclient //192.168.175.10/docs -U asha%LabPass1 --max-protocol=SMB2_02 -c pwdProtocol negotiation to server 192.168.175.10 (for a protocol between SMB2_02 and SMB2_02) failed: NT_STATUS_NOT_SUPPORTED

155.4 smbclient: authentication

  • -U user%password works but the password shows in the process list (ps).
  • -A file reads username/password from a protected auth file: use this in scripts.
  • -N skips the password: it opened the public share anonymously, but put gave ACCESS DENIED (read only).
  • -W domain, -r Kerberos realm, --use-kerberos=desired|required|off (Kerberos needs a DNS name).
Terminal
smbclient //$S/docs -A /root/.smbcred -c pwdsmbclient //$S/public -N -c lssmbclient //$S/docs -U asha%WrongPass -c lssmbclient //$S/nosuch -U asha%LabPass1 -c lssmbclient //$S/hr -U ravi%LabPass2 -c ls
Output
$ smbclient //192.168.175.10/docs -U asha%WrongPass -c lssession setup failed: NT_STATUS_LOGON_FAILURE$ smbclient //192.168.175.10/nosuch -U asha%LabPass1 -c lstree connect failed: NT_STATUS_BAD_NETWORK_NAME$ smbclient //192.168.175.10/hr -U ravi%LabPass2 -c lstree connect failed: NT_STATUS_ACCESS_DENIED

155.5 smbclient: signing, encryption, name resolution

  • --client-protection=sign requires a signature on every packet; =encrypt encrypts all traffic; =off makes both optional.
  • Server smbstatus showed ravi with AES-128-GMAC signing and asha's backup session also with AES-128-GCM encryption.
  • -R sets name lookup order (lmhosts, host = /etc/hosts + DNS, wins, bcast); -n sets the client's NetBIOS name.
Output
$ smbstatus -b; smbstatus -b | awk 'NR>4 {print $2, $6, $7, $8}'   (filesrv)Samba version 4.19.9asha SMB3_11 partial(AES-128-GCM) AES-128-GMACravi SMB3_11 - AES-128-GMAC

155.6 smbclient: tar backup and restore (-T)

  • -Tc docs.tar backs up the whole share; -TcI includes only listed paths; -TcX excludes them.
  • -Tx restores a tar into a share (here reports.tar into backup).
  • -Tcg incremental (archive bit), -Tcga resets the bit, -Tcn dry run, -d0 -Tc - writes the tar to stdout.
Terminal
smbclient //$S/docs -A /root/.smbcred -Tc docs.tarsmbclient //$S/docs -A /root/.smbcred -TcI reports.tar reportssmbclient //$S/docs -A /root/.smbcred -TcX nobig.tar big.iso logssmbclient //$S/backup -A /root/.smbcred -Tx reports.tar
Output
rc=0  reports                             D        0  Mon Nov  9 07:29:59 2026\reports  q3.txt                             AS       18  Mon Nov  9 07:28:30 2026  q4.txt                             AS        8  Mon Nov  9 07:28:30 2026  2025                                D        0  Mon Nov  9 07:29:59 2026\reports\2025  annual.txt                         AS       11  Mon Nov  9 07:28:30 2026

155.7 smbclient: logging and config

  • -d 3 is the best troubleshooting level: shows port 445 and the NTLMSSP login steps.
  • -s FILE uses another smb.conf (the lab one forced max protocol SMB2_02, so it failed).
  • --option='client max protocol=SMB3' overrides any smb.conf option on the command line.
  • smbclient --version printed Version 4.19.9.

155.8 Interactive: navigation and transfer

  • pwd, ls/dir, cd, lcd (local), du (free space), volume, allinfo (timestamps and streams), more, history.
  • get remote [local], put local [remote]; with prompt off + recurse on, mget/mput copy whole folders.
  • reget completed a file from 100000 bytes and cmp matched.
  • reput gave a 180000-byte file instead of 300000 and cmp failed: always check size and checksum after a resume.
Terminal
sc -c 'cd reports; allinfo q3.txt'sc -c 'prompt off; recurse on; mget logs'sc -c 'prompt off; mkdir csv; cd csv; mput *.csv'sc -c 'put part.iso up.iso; ls up.iso'sc -c 'reput full.iso up.iso; ls up.iso'sc -c 'get up.iso check.iso'cmp full.iso check.iso
Output
  up.iso                              A   120000  Mon Nov  9 07:30:33 2026putting file full.iso as \up.iso (35155.6 kb/s) (average 35156.2 kb/s)  up.iso                              A   180000  Mon Nov  9 07:30:36 2026-rw-r--r--    1 root     root        180000 Nov  9 07:30 check.iso-rw-r--r--    1 root     root        300000 Nov  9 07:30 full.isofull.iso check.iso differ: char 1, line 1reput: NOT the same as full.iso

155.9 Interactive: file management and UNIX extensions

  • rmdir on a non-empty folder gave DIRECTORY NOT EMPTY; deltree deletes a tree in one go.
  • rename, hardlink, setmode f +r (DOS attrs r s h a); a read-only file gave NT_STATUS_CANNOT_DELETE on del.
  • posix on SMB3 said no UNIX CIFS extensions; over NT1 (lab only) posix_whoami showed UID 1000.
  • posix_mkdir d 750, chmod 700 d (mode first in this version), symlink, readlink, posix_rmdir, posix_unlink.
Output
$ sc -c 'del meeting.txt'NT_STATUS_CANNOT_DELETE deleting remote file \meeting.txt$ sc1 -c 'posix; symlink meeting.txt m.lnk; readlink m.lnk'/m.lnk -> meeting.txt$ sc1 -c 'posix; posix_rmdir pdir; posix_unlink m.lnk'posix_rmdir deleted directory /pdirposix_unlink deleted file /m.lnk

155.10 Interactive: printing and session testing

  • print FILE on a printer share created a job; the same text reached the server's printed file.
  • queue gives an SMB1 error on SMB3; showconnect / listconnect show DFS connections.
  • echo pings the server over SMB; tid/tcon/tdis manage tree connects; logoff then ls fails; logon ravi makes a new session.
Output
$ sc -c 'logoff; ls'logoff successfulNT_STATUS_USER_SESSION_DELETED listing \*$ sc -c 'logoff; logon ravi LabPass2; tcon docs; ls meeting*'logoff successfulCurrent VUID is 0tcon to docs successful, tid: 2388100351  meeting-link.txt                   AR       21  Mon Nov  9 07:28:30 2026  meeting.txt                        AR       21  Mon Nov  9 07:28:30 2026

155.11 mount.cifs: the share becomes a folder

  • mount -t cifs calls the mount.cifs helper; mount -t smb3 allows only SMB3.
  • The kernel cifs module turns each file operation into an SMB request; apps do not know it is remote.
  • Use credentials=FILE instead of password= (a comma in the password breaks parsing).
App read on a CIFS mount
  1. 1.mount -t smb3 //filesrv/docs /mnt/docs -o credentials=...

  2. 2.App calls read() on /mnt/docs/file

  3. 3.Kernel cifs module turns it into SMB2 READ

  4. 4.Request goes through the LAN switch to filesrv:445

  5. 5.File data comes back, app sees a normal file

Output
mount -t cifs //filesrv/docs /mnt/docs \  -o credentials=/root/.smbcred \  -o vers=3.1.1,sec=ntlmssp,seal \  -o uid=1000,gid=1000 \  -o file_mode=0644,dir_mode=0755 \  -o port=445,echo_interval=30,soft
GroupKey mount.cifs options
Credentialsusername=, password=, credentials=FILE, domain=, guest, cruid=, multiuser
sec=ntlmssp (default), krb5 (best in a domain), *i variants = signing, none; seal = SMB3 encryption
vers=1.0 (SMB1, avoid), 2.0, 2.1, 3.0, 3.02, 3.1.1, default = highest SMB2+
Ownershipuid=, gid=, file_mode=, dir_mode=, forceuid, noperm, cifsacl, idsfromsid
Connectionport=445 (then 139), ip=, echo_interval=60, nosharesock, nodfs, max_credits
Server downsoft (default) returns an error, hard keeps retrying

155.12 Comparison: smbclient vs mount.cifs

Pointsmbclientmount.cifs
Runs inUser spaceKernel (cifs module)
ResultFTP-like shell: ls, get, put, tarShare appears as a local folder
Root neededNoUsually yes (mount)
Best forCopies, scripts, backups, troubleshootingApps that need normal file paths

155.13 Common mistakes

  • Thinking smbclient mounts a share: it only copies files; mounting needs mount.cifs.
  • Passing -U user%password in scripts: visible in ps; use -A.
  • Trusting reput/reget without checking size and checksum.
  • Using vers=1.0 (SMB1): weak and should be avoided.
  • Blaming the password for BAD_NETWORK_NAME: login passed, the share name is wrong.

155.14 Interview tips

  • SMB steps on 445: Negotiate (dialect), Session Setup (login), Tree Connect (share).
  • LOGON_FAILURE = login, BAD_NETWORK_NAME = share name, ACCESS_DENIED = permission.
  • Windows share from Linux: smbclient -A for copies/scripts, -Tc for backup, mount -t smb3 with credentials=, vers=3.1.1, seal for a folder.
  • smbstatus -b on the server shows dialect, signing and encryption per session.