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.
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/share02What 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
!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/share05Sources
- If users can't edit or authenticate files on a macOS hosted SMB - Apple SupportEvidence: Apple's SMB sharing and authentication guidance relevant to mount_smbfs connections.
- MOUNT Command: Mount a file system in macOSEvidence: Documents mount_smbfs syntax with //user@server/share targets and unmounting via umount/diskutil unmount.
Last verified: 2026-09-17 · Category: System & Settings