Mount an SMB Share from the Terminal with mount_smbfs

Connect to NAS and Windows shares entirely from the command line, with scriptable credentials and options.

macOSnassmbmountLow risk
Run `mount_smbfs //user@server/Share ~/mnt/share` to mount an SMB share at a local folder.

01Command

Command
$ mkdir -p ~/mnt/share && mount_smbfs //user@server/Share ~/mnt/share

02What it does

mount_smbfs is what Finder's 'Connect to Server' calls underneath, but it works over SSH and accepts options Finder hides: `-d 0770 -f 0770` for file modes, and a domain via `//DOMAIN;user@server/`. The password prompt can be avoided by embedding it in the URL (insecure) or by storing credentials in ~/Library/Preferences/nsmb.conf. `umount <path>` unmounts cleanly, or `diskutil unmount force` when a process holds it.

03Risk

RiskLow risk
!Warning: A password embedded in the mount URL is visible to every process via `ps` — never use it in shared scripts.

04Undo

Undo
$ umount ~/mnt/share

05Sources

Last verified: 2026-09-17 · Category: System & Settings