设置完虚拟机的共享文件设置
发现还是不行
然后尝试进入mnt/hgfs 时候发现权限不够 查阅网上资料后发现应该是挂载问题
问题:在VMware中的Ubuntu共享了目录发现/mnt/hgfs 一直都是root权限,而且hgfs没有写的权限 导致很多问题
网上试了很多方法发现都是无效的
比如:
chmod 777 -R
chown username:group /mnt/hgfs
usermod -aG vboxsf username
sudo chown username:username hgfs -R
sudo chmod 777 ./hgfs
都是无效的
解决方法:
首先输入vmware-hgfsclient,看看是否共享文件夹已经建立
请添加图片描述
如果之前已经挂载 hgfs,先取消挂载
sudo umount /mnt/hgfs
重新用以下命令挂载即可
sudo /usr/bin/vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other -o uid=1000 -o gid=1000 -o umask=022
【注意】上面命令中的 uid 和 gid 需要根据 ubuntu 用户 uid 来决定,在home目录输入id 命令即可查询
UserName@UserName:~$ id
uid=1000(UserName) gid=1000(UserName) 组=1000(UserName),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare)
username
如果出现下面错误:
UserName@UserName:/mnt$ sudo /usr/bin/vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other -o uid=1000 -o gid=1000 -o umask=022
fuse: mountpoint is not empty
fuse: if you are sure this is safe, use the 'nonempty' mount option
把命令改为:
sudo /usr/bin/vmhgfs-fuse .host:/ /mnt/hgfs -o nonempty -o allow_other -o uid=1000 -o gid=1000 -o umask=022
即可成功
查看权限ll或ls -l
UserName@UserName:/mnt$ ll
总用量 25
drwxrwxrwx 6 UserName root 4096 6月 9 10:17 ./
drwxr-xr-x 25 root root 4096 6月 11 11:04 …/
drwxrwxrwx 2 UserName root 4096 6月 9 10:17 cdr/
drwxr-xr-x 2 UserName root 4096 6月 9 10:13 cdrom/
drwxr-xr-x 2 UserName root 4096 6月 9 10:12 chrom/
drwxr-xr-x 1 UserName UserName 4192 6月 18 11:11 hgfs/
可以看到已经修改成功【其中除了hgfs的其他文件夹的所有者是UserName,是之前在超级用户权限下用chmod -hR UserName /mnt修改导致的,但是改不了hgfs文件夹的所有者】
对比修改之前的
drwxrwxrwx 6 UserName root 4096 6月 9 10:17 ./
drwxr-xr-x 25 root root 4096 6月 11 11:04 …/
drwxrwxrwx 2 UserName root 4096 6月 9 10:17 cdr/
drwxr-xr-x 2 UserName root 4096 6月 9 10:13 cdrom/
drwxr-xr-x 2 UserName root 4096 6月 9 10:12 chrom/
dr-xr-xr-x 1 root root 4192 6月 18 10:48 hgfs/
可以看到已经成功修改了hgfs的权限
重启发现权限又变回去,需要设置开机自动挂载
sudo vim /etc/fstab //打开配置文件
在最后一行,添加代码,设置开机自动挂载
.host:/ /mnt/hgfs fuse.vmhgfs-fuse allow_other,uid=1000,gid=1000,umask=022 0 0
重启发现开机就权限就是username了