Linux 挂载 SMB
本文最后更新于 2025年9月19日 凌晨
环境
Debian 13
内核版本 6.12.43+deb13-amd64
过程
1. 安装 CIFS 工具
1 | |
2. 创建挂载点
1 | |
3. 挂载 SMB 共享
单次挂载命令如下: 1
mount -t cifs -o username=your_username,password=your_password,uid=<uid>,gid=<gid>,iocharset=utf8,file_mode=0775,dir_mode=0775 //<ip>/<path> /mnt/<path>
为了重启后自动挂载,建议写入 /etc/fstab 文件。 1
2# /etc/fstab
//<ip>/<path> /mnt/<path> cifs credentials=/etc/samba/credentials,uid=<uid>,gid=<gid>,iocharset=utf8,file_mode=0775,dir_mode=0775,_netdev,x-systemd.automount,noauto 0 0
- _netdev: 告诉系统:这是网络文件系统,必须等网络起来后再挂载。
- x-systemd.automount: 开启自动挂载,只有在第一次访问 /mnt/downloads 时才真正挂载,不会拖慢开机。
- noauto: 防止在网络未就绪时硬挂载失败,和 automount 配合用
- 0664: 文件权限,只能读写
- 0775: 目录权限,允许读写和进入(执行)
- 0 0: 不需要 dump 和 fsck 检查
其中,credentials
指定了存放用户名和密码的文件,内容如下: 设置该文件权限为
600,以保护敏感信息: 1
2
3# /etc/samba/credentials
username=your_username
password=your_password1
chmod 600 /etc/samba/credentials
uid 和 gid
分别指定了挂载后文件的所有者和所属组,可以根据需要调整。
Linux 挂载 SMB
https://term-inator.github.io/2025/09/14/debian-mount-smb/