SkillPilotAI

File sharing: SMB and NFS

File sharing keeps one copy of a file on a server that everyone opens over the network, instead of emailing budget_final_v3.xlsx around. SMB (TCP 445) is the Windows protocol, NFS (TCP 2049) is the Unix/Linux one, and Samba lets a Linux server speak SMB to Windows clients.

136.1 Why is it used?

  • Asha and Ravi email budget.xlsx back and forth; after a few days there are five versions and nobody knows the latest.
  • A file server holds a single copy: both open and save it in place, so everyone always sees the latest version.
  • Central permissions: who can open which share, read only or read write.
  • Mixed offices: Windows gets a Z: drive over SMB, Linux machines mount the same folder over NFS.

136.2 How SMB works

SMB session: open and read a file (TCP 445)
  1. 1.Negotiate: laptop 192.168.156.20 offers dialects 2.0.2, 2.1, 3.0, 3.0.2, 3.1.1

  2. 2.Server filesrv 192.168.156.10 picks the newest common: 0x0311 (SMB 3.1.1)

  3. 3.Session Setup: login with NTLM (or Kerberos), User: asha

  4. 4.Tree Connect \\192.168.156.10\docs: server checks access, returns a Tree ID

  5. 5.Create notes.txt -> Read Len:21 -> data: Team meeting at 4 pm

  6. 6.Close and Tree Disconnect clean up

VersionYear / OSWhat it brought
SMB1 / CIFSOldChatty; WannaCry exploited it: keep it disabled
SMB 2.0 / 2.1Vista, Server 2008Fewer commands, bigger reads
SMB 3.0 / 3.0.2Server 2012Encryption, multichannel
SMB 3.1.1Windows 10+Pre-authentication integrity, AES-GCM

136.3 Lab: Samba config and smbclient

Output
[global]  server min protocol = SMB2  smb ports = 445  map to guest = never[docs]  path = /srv/docs  read only = no  valid users = asha ravi[reports]  path = /srv/reports  read only = yes[hr]  path = /srv/hr  valid users = asha
Terminal
smbclient -L //192.168.156.10 -U asha%LabPass1smbclient //192.168.156.10/docs \  -U asha%LabPass1 -c 'ls;  get notes.txt /tmp/notes.txt;  put /tmp/hello.txt hello.txt; ls'
Output
  Sharename       Type      Comment  docs            Disk  reports         Disk  hr              Disk  IPC$            IPC       IPC Service (Samba 4.19.9)SMB1 disabled -- no workgroup available getting file \notes.txt of size 21 as /tmp/notes.txtputting file /tmp/hello.txt as \hello.txt  hello.txt                           A       18  Mon Nov  9 04:21:45 2026  notes.txt                           N       21  Mon Nov  9 04:21:31 2026  budget.xlsx                         N       27  Mon Nov  9 04:21:31 2026

136.4 tshark: the SMB2 flow in packets

Terminal
tcpdump -i eth0 -U -w /tmp/smb.pcap \  tcp port 445 &tshark -r /tmp/smb.pcap -Y smb2 -T fields \  -e frame.number -e ip.src -e _ws.col.Infotshark -r /tmp/smb.pcap -T fields \  -e smb2.dialect -Y 'smb2.cmd==0'
Output
4  192.168.156.20  Negotiate Protocol Request6  192.168.156.10  Negotiate Protocol Response8  192.168.156.20  Session Setup Request, NTLMSSP_NEGOTIATE9  192.168.156.10  Session Setup Response, Error:    STATUS_MORE_PROCESSING_REQUIRED, NTLMSSP_CHALLENGE10  192.168.156.20  Session Setup Request, NTLMSSP_AUTH,    User: MYGROUP\asha11  192.168.156.10  Session Setup Response18  192.168.156.20  Tree Connect Request Tree: \\192.168.156.10\docs19  192.168.156.10  Tree Connect Response20  192.168.156.20  Create Request File: notes.txt24  192.168.156.20  Read Request Len:21 Off:0 File: notes.txt25  192.168.156.10  Read Response26  192.168.156.20  Close Request File: notes.txt28  192.168.156.20  Tree Disconnect Request 0x0202,0x0210,0x0300,0x0302,0x03110x0311
  • NTLM login takes two Session Setup rounds: NEGOTIATE -> CHALLENGE (MORE_PROCESSING_REQUIRED) -> AUTH.
Terminal
smbclient //192.168.156.10/docs -U asha%LabPass1 -m SMB2smbstatus -b                 # serversmbclient //192.168.156.10/docs -U asha%LabPass1 -m SMB3smbclient //192.168.156.10/docs \  -U asha%LabPass1 \  --option='client min protocol=NT1' \  --option='client max protocol=NT1' -c ls
Output
PID  Username  Machine         Protocol Version  Signing112  asha      192.168.156.20  SMB2_10           partial(HMAC-SHA256)125  asha      192.168.156.20  SMB3_11           partial(AES-128-GMAC) smbXcli_negprot_smb1_done: No compatible protocol selected by server.protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE

136.5 Share permissions vs file permissions

  • Level 1, share permission: which user can open which share, read only or read write (checked at Tree Connect).
  • Level 2, file permission: NTFS ACL on Windows, owner and mode bits on Linux.
  • Effective access = the stricter of the two.
ShareUsersAccessRavi's result
docsasha, raviread writeCan write, but budget.xlsx (owner asha, rw-r--r--) -> ACCESS_DENIED
reportsasha, raviread onlyget q3.txt OK, put x.txt -> ACCESS_DENIED
hrasharead writetree connect failed: ACCESS_DENIED
Output
getting file \q3.txt of size 18 as /tmp/q3.txtNT_STATUS_ACCESS_DENIED opening remote file \x.txt $ smbclient //192.168.156.10/hr -U ravi%LabPass2 -c lstree connect failed: NT_STATUS_ACCESS_DENIED $ smbclient ... /docs -U ravi ... budget.xlsxNT_STATUS_ACCESS_DENIED opening remote file \budget.xlsx$ smbclient ... /docs -U asha ... budget.xlsxputting file /tmp/hello.txt as \budget.xlsx

136.6 How NFS works

NFSv3: rpcbind, mountd, file handle, READ
  1. 1.Client asks rpcbind on TCP 111: GETPORT MOUNT(100005) V:3

  2. 2.Reply: Port 2049 (mountd and nfs both on 2049 here)

  3. 3.MOUNT V3 MNT Call /srv/nfs (checked against /etc/exports)

  4. 4.MNT Reply OK with file handle FH: 0xcf4a7d92

  5. 5.NFS READ release.txt to 192.168.156.10:2049 using the handle

NFSv4 uses only TCP 2049, no rpcbind/mountd needed

Terminal
cat /etc/exports            # serverrpcinfo -p 192.168.156.10   # clientshowmount -e 192.168.156.10
Output
/srv/nfs 192.168.156.0/24(ro)/srv/build 192.168.156.20(rw,no_root_squash)    program vers proto   port  service    100000    4   tcp    111    100003    3   tcp   2049    100005    1   tcp   2049    100005    3   tcp   2049 Export list for 192.168.156.10:/srv/nfs   192.168.156.0/24/srv/build 192.168.156.20
Terminal
nfs-cat nfs://192.168.156.10/srv/nfs/release.txtnfs-cp /tmp/b.txt nfs://192.168.156.10/srv/nfs/b.txtnfs-cp /tmp/b.txt nfs://192.168.156.10/srv/build/b.txtnfs-ls nfs://192.168.156.10/srv/hr
Output
build v1.4 ok Failed to creat file /b.txt: creat call failed with"NFS: CREATE of /b.txt failed with NFS3ERR_ROFS(-30)" copied 5 bytes Failed to mount nfs share : mount_cb: RPC error:Mount failed with error MNT3ERR_ACCES(13)Permission denied(13)
  • ro export -> writes fail with ROFS (read-only file system).
  • rw only for 192.168.156.20 (build server); no_root_squash lets that client's root act as root: use carefully.
  • Folder not exported (/srv/hr) -> mountd returns permission denied.

136.7 Mounting shares

Output
# Linux: NFS export mountsudo mount -t nfs4 filesrv:/srv/nfs /mnt/nfs# /etc/fstab: auto mount at bootfilesrv:/srv/nfs /mnt/nfs nfs4 ro,_netdev 0 0# Linux: SMB share mount (cifs-utils)sudo mount -t cifs //filesrv/docs /mnt/docs \  -o username=asha,vers=3.1.1# Windows: map the SMB share as Z:net use Z: \\filesrv\docs /user:asha# Windows: with the NFS client featuremount -o anon \\filesrv\srv\nfs N:

136.8 Comparison: SMB vs NFS

PointSMBNFS
WorldWindows (Samba on Linux)Unix / Linux
PortTCP 445TCP 2049 (+111 rpcbind for v3)
IdentityUser login: AD / Kerberos / NTLMUID / GID of the client (Kerberos in v4)
Access controlShare permissions + NTFS ACL/etc/exports options + file mode bits
EncryptionSMB 3 encryptionNFSv4 with Kerberos (krb5p)
Client viewZ: drive / mount -t cifsmount -t nfs4 / fstab

136.9 Common mistakes

  • Exposing port 445 to the internet because the password is strong: WannaCry used an SMB1 bug and needed no password. Keep SMB on LAN/VPN, SMB1 off, block 445 outbound.
  • Forgetting the second permission level: a read-write share does not override a read-only file ACL.
  • Exporting with no_root_squash or to a whole subnet when one host is enough.
  • Leaving SMB1 enabled for old devices.

136.10 Interview tips

  • SMB vs NFS: Windows, TCP 445, AD/NTLM login, share + NTFS perms vs Unix, TCP 2049, exports + UID/GID.
  • SMB flow: Negotiate -> Session Setup -> Tree Connect -> Create/Read/Write -> Close.
  • Effective permission = the stricter of share and file permission.
  • Security: SMB 3 encryption and SMB1 disabled; NFSv4 with Kerberos.