用 mount_smbfs 在终端挂载 SMB 共享
完全通过命令行连接 NAS 和 Windows 共享,凭据和挂载选项均可脚本化。
运行 `mount_smbfs //user@server/Share ~/mnt/share` 把 SMB 共享挂载到本地文件夹。
01命令
命令
$ mkdir -p ~/mnt/share && mount_smbfs //user@server/Share ~/mnt/share02作用说明
mount_smbfs 正是访达"连接服务器"背后调用的工具,但它可以在 SSH 下使用,还接受访达隐藏的选项:`-d 0770 -f 0770` 设置文件权限,`//DOMAIN;user@server/` 指定域账号。避免交互输密码可以把密码写进 URL(不安全),或存入 ~/Library/Preferences/nsmb.conf。`umount <路径>` 可正常卸载,被进程占用时用 `diskutil unmount force`。
03风险
!注意: 把密码写进挂载 URL 后任何进程都能通过 `ps` 看到,共享脚本中切勿这样写。
04撤销
撤销
$ umount ~/mnt/share05来源
- If users can't edit or authenticate files on a macOS hosted SMB - Apple Support依据: Apple's SMB sharing and authentication guidance relevant to mount_smbfs connections.
- MOUNT Command: Mount a file system in macOS依据: Documents mount_smbfs syntax with //user@server/share targets and unmounting via umount/diskutil unmount.
最后验证: 2026-09-17 · 分类: 系统与设置