温馨提示×

linux mount cifs怎么配

小樊
44
2026-09-11 07:03:45
栏目: 智能运维

在 Linux 下挂载 Windows 共享(CIFS / SMB)通常用 mount.cifs(来自 cifs-utils)。下面从安装 → 基本挂载 → /etc/fstab → 常见问题一步步说。


一、安装 cifs 工具

Debian / Ubuntu

sudo apt update
sudo apt install cifs-utils

RHEL / CentOS / Rocky / Alma

sudo yum install cifs-utils
# 或
sudo dnf install cifs-utils

二、一次性手动挂载(最常用)

基本命令

sudo mount -t cifs //192.168.1.100/share /mnt/share \
  -o username=winuser,password=winpass

说明:

  • //192.168.1.100/share:Windows 共享路径
  • /mnt/share:本地挂载点(需提前建好)
  • username / password:Windows 用户名和密码

推荐方式(密码不写在命令行)

sudo mkdir -p /mnt/share
sudo mount -t cifs //192.168.1.100/share /mnt/share \
  -o credentials=/etc/cifs-creds.conf

/etc/cifs-creds.conf 内容:

username=winuser
password=winpass
domain=WORKGROUP

权限:

sudo chmod 600 /etc/cifs-creds.conf

三、常用挂载参数(很重要)

-o username=xxx,password=xxx,uid=1000,gid=1000,file_mode=0644,dir_mode=0755,iocharset=utf8

常用选项说明:

参数 作用
uid=1000 挂载后文件属主
gid=1000 挂载后文件属组
file_mode=0644 文件权限
dir_mode=0755 目录权限
iocharset=utf8 中文支持
vers=2.1 / 3.0 SMB 协议版本
nofail 开机失败不影响启动
x-systemd.automount 按需挂载

四、写入 /etc/fstab(开机自动挂载)

//192.168.1.100/share  /mnt/share  cifs  credentials=/etc/cifs-creds.conf,uid=1000,gid=1000,iocharset=utf8,vers=3.0,nofail  0  0

测试:

sudo mount -a

五、常见问题排查

1. 报 Host is down

通常是 SMB 版本问题:

-o vers=2.0
# 或
-o vers=2.1
# 或
-o vers=3.0

2. 权限不足

加:

uid=你的用户id,gid=你的组id

3. 中文乱码

iocharset=utf8

4. 域名登录

domain=CORP

六、卸载

sudo umount /mnt/share

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

  • Linux 发行版
  • Windows 版本
  • 是否域环境
  • 报错信息

我可以直接帮你写一条可用的 mount 命令

0