SkillPilotAI

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

The last SMB part covers the rest of Samba's net tool: remote shares, open files and sessions, lookup and cache, SIDs and group mapping, net rpc and net ads, the local SAM and idmap databases, usershares, registry-based config (net conf / net registry) and the small helpers. net manages remote servers over RPC and also edits the local Samba databases.

159.1 Why is it used?

  • Add, list and delete shares on a remote server without editing smb.conf by hand.
  • See who has which file open and close stuck files.
  • Map Windows SIDs to Unix groups (groupmap) so permissions work.
  • Edit local accounts and policies (net sam), and create shares live via the registry (net conf).
  • Where: Linux samba-common-tools; Windows net.exe is a different command; macOS uses smbutil. Lab: Alpine 3.20, Samba 4.19.9, 192.168.179.0/24.

159.2 How it works: remote vs local commands

  • net rpc ... travels over SMB 445 to a named pipe on IPC$ (srvsvc for shares, samr for users).
  • net ads ... talks to Active Directory over LDAP and Kerberos.
  • net sam, net conf, net registry, net idmap, net cache run locally on the server and edit its tdb files.
net rpc share add
  1. 1.Client 192.168.179.20: net rpc share add 'archive=/srv/reports' -S 192.168.179.10

  2. 2.Request goes over SMB 445 to IPC$ \srvsvc (DCE/RPC NetShareAdd)

  3. 3.smbd on FILESRV runs its add share command

  4. 4.New share archive is saved in the registry

  5. 5.net rpc share list now shows docs, IPC$ and archive

net sam / conf / registry skip the network: they run on the server itself

159.3 Shares, files and sessions

  • net rpc share list / add NAME=PATH -C comment -M maxusers / delete NAME.
  • net rpc file first exited with code 5 (access denied): root's token had no BUILTIN\Administrators.
  • After net groupmap add sid=S-1-5-32-544 unixgroup=root, file list, file user and file close worked (4.19 has no file info).
  • There is no net rpc session; net rap session needs SMB1 and fails on SMB3.11. On the server use net status sessions / shares.
Terminal
SRV=192.168.179.10net rpc share add 'archive=/srv/reports' \  -C 'Q3 archive' -M 25 -S $SRV -U rootnet rpc share delete archive -S $SRV -U rootnet rpc file -S $SRV -U root# n159-srv (root):net groupmap add sid=S-1-5-32-544 \  unixgroup=root type=builtin \  ntgroup=Administratorsnet rpc file user asha -S $SRV -U rootnet rpc file close 6225923 -S $SRV -U root
Output
$ net rpc file info 6225923 -S $SRV -U rootInvalid command: net rpc file info$ net rpc file close 6225923 -S $SRV -U root(exit 0)[srv]$ smbstatus -LNo locked files[srv]$ net status sessionsPID     Username      Group         Machine     95   asha          asha          192.168.179.20 (ipv4:192.168.179.20:36868)[srv]$ net status sharesService      pid     machine       Connected atdocs         95   192.168.179.20  Mon Nov  9 07:29:53 2026

159.4 Lookup and cache

  • net lookup host FILESRV -> 192.168.179.10; lookup master LAB -> master browser.
  • AD lookups: lookup ldap / kdc / dc via DNS; lookup name / sid convert names and SIDs.
  • Answers are stored in gencache: net cache list shows NBT keys; cache add/set/del/search/flush manage it (TTL in s m h d w).
Terminal
net lookup host FILESRVnet lookup master LABnet cache listnet cache add labkey 'n159 data' 1hnet cache search 'lab*'net cache flush; net cache list
Output
$ net cache add labkey 'n159 data' 1hNew cache entry stored successfully.$ net cache search 'lab*'Key: labkey   Timeout: 08:30:31   Value: n159 data$ net cache flush; net cache list(exit 0)

159.5 SIDs and group mapping

  • getlocalsid prints the machine SID; getdomainsid shows the same (standalone server has no domain SID).
  • maxrid: highest RID 1001 (root); setlocalsid / setdomainsid help in migrations; rpc getsid fetches a DC's SID.
  • groupmap add mapped Unix group engineers to RID 1002 as a domain group; groupmap modify / delete change it.
Output
$ net groupmap listAdministrators (S-1-5-32-544) -> root$ net groupmap add ntgroup='Engineers' ...Got RID 1002Successfully added group Engineers to the mapping db as a domain group$ net groupmap list verbose ntgroup=Engineers	SID       : S-1-5-21-4244435295-166611574-740175049-1002	Unix group: engineers	Group type: Domain Group

159.6 net rpc and net ads

  • net rpc info: domain LAB, SID and 2 users; rights list shows privileges (SeRemoteShutdownPrivilege...).
  • trustdom list: none (standalone); shutdown on the lab server gave WERR_ACCESS_DENIED (no shutdown script).
  • Other rpc: trustdom add/del/establish, rights grant/revoke, abortshutdown, samdump/vampire (copy from an NT4 PDC).
  • net ads needs AD: ads info found no LDAP server, gpo listall 'No logon servers', testjoin not valid, keytab list needs a keytab kerberos method.
  • In AD: gpo list/apply, dns register, printer publish, search '(LDAP filter)', keytab create/add, setspn, enctypes set ACCOUNT 24 (AES128 + AES256).
Output
$ net rpc shutdown -t 60 -C 'N159 lab test' -S $SRV -U rootShutdown of remote machine failedresult was: WERR_ACCESS_DENIED(exit 255)[srv]$ net ads testjoinJoin to domain is not valid: NT code 0xfffffff6[srv]$ net ads keytab listads_keytab_open: Invalid kerberos method set (0)Warning: "kerberos method" must be set to a keytab method to use keytab functions.

159.7 net sam: local accounts and policies

  • list users verbose shows RIDs; show asha gives the full SID; policy list shows 10 policies (min password length = 5).
  • set fullname / comment / homedir / disable / pwnoexp / pwdmustchangenow change account fields and flags.
  • createlocalgroup, mapunixgroup, addmem / delmem / listmem, rights grant NAME PRIV.
  • policy set P VALUE takes numbers or forever/never/off; provision needs LDAP + winbindd.
Terminal
net sam list users verbosenet sam show ashanet sam policy show 'min password length'net sam set fullname asha 'Asha Rao'net sam set comment asha 'Finance team'pdbedit -v asha | \  grep -E 'Full Name|Account desc'
Output
$ net sam set fullname asha 'Asha Rao'Updated fullname for FILESRV\asha to Asha Rao$ net sam set comment asha 'Finance team'Updated comment for FILESRV\asha to Finance team$ pdbedit -v asha | grep -E 'Full Name|Account desc'Full Name:            Asha RaoAccount desc:         Finance team

159.8 net idmap

  • idmap maps SIDs to Unix UIDs/GIDs; winbindd creates the database (not running in the lab, so dump failed).
  • idmap check needs a terminal or --auto; -T is a dry run, -r / -a repair.
  • restore, set/get/delete range (autorid backend), delete mapping.
Output
$ net idmap checkcheck database: /var/lib/samba/winbindd_idmap.tdbInteractive use needs tty, use --auto(exit 255)

159.9 usershare and net conf (registry shares)

  • usershare lets a non-root user share a folder; ACL 'asha:F' failed (no winbindd to turn names into SIDs), 'S-1-1-0:R' (Everyone read) worked.
  • net conf keeps config in the Samba registry instead of smb.conf: addshare, setparm, getparm, delshare, import -T (test), drop (deletes all!).
  • With registry shares, smbd reads the registry on every new connection: the new reports share worked without a restart.
  • net rpc conf does the same on a remote server.
Live share with net conf (no restart)
  1. 1.Server: net conf addshare reports /srv/reports writeable=n guest_ok=N

  2. 2.net conf setparm reports 'valid users' 'asha'

  3. 3.Stored under HKLM\Software\Samba\smbconf\reports

  4. 4.Client: smbclient //192.168.179.10/reports -U asha -c ls

  5. 5.smbd reads the registry for the new connection -> q3.txt listed

Terminal
net usershare add music /home/asha/music \  'Asha music' 'S-1-1-0:R' guest_ok=nnet usershare list --longnet conf addshare reports /srv/reports \  writeable=n guest_ok=N 'Q3 reports'net conf setparm reports 'valid users' 'asha'net conf getparm reports 'valid users'# client, without smbd restart:smbclient //$SRV/reports -U asha -c ls
Output
[client]$ smbclient //$SRV/reports -U asha -c ls  .                     D        0  Mon Nov  9 07:29:35 2026  ..                    D        0  Mon Nov  9 07:29:35 2026  q3.txt                N       18  Mon Nov  9 07:29:35 2026

159.10 net registry

  • enumerate KEY shows subkeys and values (REG_SZ path, comment, valid users).
  • getvalue gives type + value, getvalueraw only the value; setvalue sz / multi_sz / dword.
  • createkey, deletekey[_recursive], getsd_sddl / setsd_sddl, import / export .reg.
  • check verified registry.tdb version 3; -r / -a repair.
Terminal
K='HKLM\Software\Samba\smbconf'net registry enumerate "$K\reports"net registry getvalue "$K\reports" pathnet registry getvalueraw "$K\reports" commentnet registry check
Output
$ net registry checkCheck database: /var/lib/samba/registry.tdbINFO: version = 3

159.11 Helpers: eventlog, g_lock, tdb, dom, offlinejoin, help

  • eventlog dump/import/export .evt files; g_lock locks (none in lab); tdb locking KEY (key must be 24 bytes).
  • net dom join / unjoin / renamecomputer manage remote Windows PCs in a domain.
  • offlinejoin provision creates an AD machine account in advance (defpwd is easy to guess: avoid).
  • net help lists all command groups.
Output
$ net helpnet rpc             Run functions using RPC transportnet ads             Run functions using ADS transportnet sam             Functions on the SAM databasenet idmap           IDmap functionsnet usershare       Manage user-modifiable sharesnet conf            Manage Samba registry based configurationnet registry        Manage the Samba registrynet tdb             Show information from tdb recordsnet vfs             Filesystem operation through the VFS stack

159.12 Comparison: where each net group works

GroupRuns overUsed for
net rpcSMB 445 + IPC$ pipesShares, files, rights, info, trusts
net adsLDAP + KerberosAD join, GPO, DNS, keytab, SPN
net rapSMB1 RAPLegacy servers only
net samLocal passdbAccounts, groups, policies
net conf / registryLocal registry.tdbLive shares and config
net idmapwinbindd idmap tdbSID <-> UID/GID mappings
net cache / lookupgencache / name resolutionCached answers, name to IP/SID

159.13 Common mistakes

  • Correct root password but net rpc file exits 5: map S-1-5-32-544 to root with net groupmap add.
  • Restarting smbd after net conf addshare: not needed with registry shares.
  • Running net conf drop casually: it deletes the whole registry config.
  • Expecting net ads to work on a standalone server.
  • Using user names in usershare ACLs without winbindd (use SIDs).

159.14 Interview tips

  • net rpc = shares/files/rights over named pipes on 445; net ads = AD over LDAP + Kerberos; net sam/conf/registry = local tdb files.
  • Exit code 5 = access denied: check the BUILTIN\Administrators mapping.
  • net conf + registry shares give live config changes without restarting smbd.
  • enctypes 24 = AES128 + AES256 only (bitmask 8 + 16).