按照一般的思路,我们先将文件夹挂载上去,命令如下:
mkdir /mnt/share_software
mount //192.9.206.43/share_software /mnt/share_software -o username="edures",password="tj$123"
然后进入到 /mnt/share_software 目录里,查看当前所有文件,发现,所属者和所属组都是root,尝试着用chown和chmod命令去修改,结果是Permission denied。
在网上查阅了相关信息,原来参数-o还可以加入以某个账号的uid和gid的方式挂载,挂载成功后该目录下的所有文件属性都属于这个账号了,
比如说,我想让 /mnt/share_software 所属用户、用户组分别为 www、www。首先,得通过如下命令查找出 用户www的uid,和用户组www的guid分别为多少:
[root@localhost ~]# cat /etc/passwd
......
www:x:501:501::/home/www:/bin/sh
mysql:x:502:502::/home/mysql:/usr/sbin/nologin
mongodb:x:503:503::/home/mongodb:/usr/sbin/nologin
......
如上所示,www的uid为501,gid为501,最后调整挂载命令如下:
#先删除掉先前的挂载
umount /mnt/share_software #挂载后,让Linux目录所属用户和用户组分别为 www:www
mount //192.9.206.43/share_software /mnt/share_software -o username="edures",password="tj$123",uid="501",gid="501"
开机自动挂载:
在文件 /etc/rc.local 中(用root用户)追加如下上述命令:
mount //192.9.206.43/share_software /mnt/share_software -o username="edures",password="tj$123",uid="501",gid="501"
挂载出现问题汇总:
一、挂载时,用户/密码错误
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
对应 /var/log/messages 记录
Oct 12 16:20:01 localhost kernel: Status code returned 0xc000006d NT_STATUS_LOGON_FAILURE
Oct 12 16:20:01 localhost kernel: CIFS VFS: Send error in SessSetup = -13
Oct 12 16:20:01 localhost kernel: CIFS VFS: cifs_mount failed w/return code = -13
二、没有分享目录
Retrying with upper case share name
mount error(6): No such device or address
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
对应 /var/log/messages 记录
Oct 12 16:20:06 localhost kernel: CIFS VFS: cifs_mount failed w/return code = -6
Oct 12 16:20:17 localhost kernel: CIFS VFS: cifs_mount failed w/return code = -6
Oct 12 16:20:17 localhost kernel: CIFS VFS: cifs_mount failed w/return code = -6
有时候还是会挂载失败,提示登录失败,那就后输入密码吧:
mount //192.9.206.43/share_software /mnt/share_software -o username="edures",uid="500",gid="500"
再输入密码 tj$123
【附】Linux挂载Linux: mount -t nfs 172.16.8.113:/mnt/reslib /mnt/reslib -o proto=tcp -o nolock
参考: