在 Ubuntu 上挂载 SMB(Samba)共享目录,常用有两种方式:临时挂载 和 开机自动挂载。下面分步骤说明。
sudo apt update
sudo apt install cifs-utils
比如要挂载到 /mnt/smb:
sudo mkdir -p /mnt/smb
sudo mount -t cifs //服务器IP/共享名 /mnt/smb \
-o username=用户名,password=密码
示例:
sudo mount -t cifs //192.168.1.100/share /mnt/smb \
-o username=test,password=123456
sudo mount -t cifs //192.168.1.100/share /mnt/smb \
-o username=test,password=123456,uid=1000,gid=1000,iocharset=utf8
uid/gid可用id 用户名查看
避免 root 独占目录
sudo nano /etc/smb.cred
内容:
username=test
password=123456
domain=WORKGROUP
(没有域可以删掉 domain)
sudo chmod 600 /etc/smb.cred
sudo mount -t cifs //192.168.1.100/share /mnt/smb \
-o credentials=/etc/smb.cred
/etc/fstabsudo nano /etc/fstab
添加一行:
//192.168.1.100/share /mnt/smb cifs credentials=/etc/smb.cred,iocharset=utf8 0 0
测试是否正确:
sudo mount -a
Host is downsudo mount -t cifs //IP/共享 /mnt/smb \
-o username=xxx,password=xxx,vers=2.0
SMB1 已默认关闭,Windows 10/11 常用 vers=2.0 或 3.0
iocharset=utf8
uid=1000,gid=1000,file_mode=0644,dir_mode=0755
其他位置smb://192.168.1.100/share
如果你愿意,可以告诉我:
我可以给你一条完全适配的命令 ✅