温馨提示×

centos怎么挂载cifs

小樊
37
2026-08-30 04:59:58
栏目: 智能运维

在 CentOS 上挂载 CIFS(SMB) 共享目录,可以按下面步骤来。


一、安装 CIFS 工具

CentOS 7

yum install -y cifs-utils

CentOS 8 / Stream

dnf install -y cifs-utils

安装完成后会提供 mount.cifs


二、创建挂载点

mkdir -p /mnt/cifs

三、手动挂载 CIFS(最常用)

1️⃣ 使用用户名密码挂载

mount -t cifs //服务器IP/共享名 /mnt/cifs \
  -o username=用户名,password=密码

示例:

mount -t cifs //192.168.1.100/share /mnt/cifs \
  -o username=admin,password=123456

2️⃣ 指定 SMB 版本(常见问题)

有些 Windows / NAS 需要指定 SMB 版本:

mount -t cifs //192.168.1.100/share /mnt/cifs \
  -o username=admin,password=123456,vers=2.0

常见版本:

  • vers=1.0(老设备)
  • vers=2.0
  • vers=2.1
  • vers=3.0(Windows 10 / Server 2016+)

3️⃣ 使用指定 UID / GID(推荐)

避免权限问题:

mount -t cifs //192.168.1.100/share /mnt/cifs \
  -o username=admin,password=123456,uid=1000,gid=1000

四、使用凭证文件(更安全)

1️⃣ 创建凭证文件

vim /etc/cifs.pass

内容:

username=admin
password=123456

2️⃣ 设置权限

chmod 600 /etc/cifs.pass

3️⃣ 挂载

mount -t cifs //192.168.1.100/share /mnt/cifs \
  -o credentials=/etc/cifs.pass

五、开机自动挂载(/etc/fstab)

编辑:

vim /etc/fstab

添加一行:

//192.168.1.100/share  /mnt/cifs  cifs  credentials=/etc/cifs.pass  0  0

或:

//192.168.1.100/share  /mnt/cifs  cifs  username=admin,password=123456  0  0

⚠️ 不推荐明文密码在 fstab

测试 fstab 是否生效:

mount -a

六、常见错误排查

❌ 报错:Host is down

host is down

✅ 解决:指定 SMB 版本

vers=2.0

❌ 报错:Permission denied

Permission denied

✅ 检查:

  • 用户名 / 密码
  • 共享目录权限
  • uid / gid 是否匹配

❌ SELinux 问题

setenforce 0

或永久关闭:

vim /etc/selinux/config
SELINUX=disabled

七、卸载 CIFS

umount /mnt/cifs

或:

umount -l /mnt/cifs

如果你愿意,可以告诉我:

  • CentOS 版本
  • 是连 WindowsNAS(群晖/威联通) 还是 Linux Samba
  • 报错信息

我可以给你一条完全适合你环境的挂载命令

0