用 mount -t cifs 挂载 Windows/NAS 共享文件夹

用 cifs-utils 把 SMB 网络共享挂载到 Linux 本地目录,让 NAS 或 Windows 上的文件像本地文件一样使用。

LinuxNASCIFS 共享挂载中风险
运行 sudo mount -t cifs //SERVER/share /mnt/nas -o username=youruser,uid=$(id -u),输入共享密码即可。

01命令

命令
$ sudo mount -t cifs //192.168.1.20/share /mnt/nas -o username=youruser,uid=$(id -u),iocharset=utf8

02作用说明

内核的 cifs 客户端可以连接任意 SMB 共享——Windows 电脑、群晖/威联通 NAS 或 Samba 服务器——并挂到指定目录下。设置 uid=$(id -u) 后挂载的文件归你的用户所有,不用 sudo 就能读写;iocharset=utf8 保证中文文件名不乱码。重启后挂载会消失,需要自动重连就把条目写进 /etc/fstab(用 credentials=文件名,chmod=600)或配 systemd 自动挂载。

03风险

风险中风险
使用条件cifs-utils (sudo apt install cifs-utils); kernel cifs module
!注意: 不要把共享密码明文直接写进 /etc/fstab,应使用 root 所有、权限 600 的凭据文件;挂载前先确认挂载点目录已创建。

04撤销

撤销
$ sudo umount /mnt/nas

05来源

  • Samba — Arch Wiki
    Arch Wiki · community · 2026-09-17
    依据: Covers mounting SMB/CIFS shares on Linux with cifs-utils, mount options, and fstab credentials files.
  • mount.cifs(8) — Ubuntu manual page
    Canonical · community · 2026-09-17
    依据: Documents mounting SMB/CIFS shares via mount -t cifs, including username, uid, and iocharset options.

最后验证: 2026-09-18 · 分类: 网络