技術文章 · IT 指令工具箱

SMB、NFS 掛載指令:Linux、macOS、Windows 網路磁碟

整理 Linux mount.cifs/NFS、macOS mount_smbfs/NFS、Windows net use 與 PowerShell SMB 查詢,包含測試掛載、credentials、權限與卸載。

作者 Steve Chen · 發布  · 約 5 分鐘閱讀

IT 指令工具箱 — 廷皓技術專欄插圖

掛載失敗要分成 DNS/路由、port、身分驗證、share 名稱、SMB/NFS 版本與本機權限。先做暫時性掛載,成功後再寫進 fstab 或自動掛載。

21 組範例LinuxmacOSWindows查核日期:2026-08-11
動手前:不要把密碼直接寫在命令列或 fstab。正式掛載前確認是否會遮住既有目錄內容;卸載前確認沒有程序正在使用。

Linux SMB/CIFS

安裝前先列 SMB server 共享Linux smbclient

smbclient -L //fileserver.example.com -U username

會互動要求密碼;需安裝 smbclient。

建立掛載點Linux

sudo install -d -m 0750 /mnt/teamshare

確認目錄原本沒有重要內容。

使用 credentials file 掛載 SMBLinux

sudo mount -t cifs //fileserver.example.com/team /mnt/teamshare -o credentials=/root/.smb-team,vers=3.1.1,uid=1000,gid=1000

credentials 檔權限應設 600;uid/gid 依現場調整。

唯讀掛載 SMBLinux

sudo mount -t cifs //fileserver.example.com/team /mnt/teamshare -o credentials=/root/.smb-team,vers=3.1.1,ro

適合先驗證讀取,降低誤寫風險。

查看 CIFS 掛載Linux

findmnt -t cifs

確認來源、目的與 mount options。

卸載 SMBLinux

sudo umount /mnt/teamshare

若 busy,先用 lsof 或 fuser 找使用者,不要急著 lazy unmount。

Linux/macOS NFS

查看 NFS server exportsLinux

showmount -e nfs.example.com

NFSv4 環境不一定允許或需要 mountd/showmount。

Linux 暫時掛載 NFSv4Linux

sudo mount -t nfs4 nfs.example.com:/export/team /mnt/team

先建立空掛載點並確認防火牆。

Linux 唯讀掛載 NFSLinux

sudo mount -t nfs4 -o ro nfs.example.com:/export/team /mnt/team

先做讀取驗證。

查看 NFS 掛載Linux

findmnt -t nfs,nfs4

確認版本與 mount options。

macOS 掛載 NFSmacOS

sudo mount_nfs -o vers=4 nfs.example.com:/export/team /Volumes/team

先建立 /Volumes/team,參數依 server 版本調整。

查看 NFS client 統計Linux

nfsstat -c

用於觀察 client RPC 與錯誤。

卸載 NFSLinux/macOS

sudo umount /mnt/team

macOS 目的路徑要換成 /Volumes/...。

macOS/Windows SMB

macOS 掛載 SMBmacOS

mkdir -p ~/Volumes/team && mount_smbfs '//[email protected]/team' ~/Volumes/team

會互動要求密碼;特殊字元需 URL encoding。

macOS 查看 SMB 連線macOS

smbutil statshares -a

列出目前 SMB share 與 dialect。

macOS 卸載macOS

diskutil unmount ~/Volumes/team

若 busy,先關閉 Finder 與使用中的程序。

Windows 連線網路磁碟Windows CMD

net use Z: \\fileserver.example.com\team /user:DOMAIN\username *

星號會互動要求密碼,避免寫在命令列。

Windows 列出網路連線Windows CMD

net use

確認 drive letter 與 UNC。

Windows 移除指定連線Windows CMD

net use Z: /delete

會中斷使用該 drive 的程式。

PowerShell 看 SMB 連線Windows PowerShell

Get-SmbConnection

顯示 server、share、user 與 dialect。

PowerShell 看 SMB mappingWindows PowerShell

Get-SmbMapping

用於檢查 UNC 與 local path。

怎麼確認有做對

  • 掛載後用 mount/findmnt/Get-SmbConnection 確認實際版本與來源。
  • 先做小檔讀寫與 checksum,再測大檔。
  • 重開機後若需自動掛載,確認憑證與網路就緒順序。

常見錯誤

  • 密碼明文寫在 fstab 或命令列。
  • 掛載到非空目錄,把原內容暫時遮住。
  • SMB dialect 或 NFS version 直接硬降而沒查根因。
  • 遇到 busy 就用強制或 lazy unmount。

版本與官方文件

參數會隨工具版本與作業系統實作改變。正式環境先用 --help、-h 或系統內建說明確認,再以當版官方文件為準。

聯絡廷皓討論 看更多文章