參考https://jarviswwong.com/ubuntu-vmware-hgfs-permissions-problem.html
問題:在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
都是無效的
解決方法
看到https://jarviswwong.com/ubuntu-vmware-hgfs-permissions-problem.html之后解決了問題
1.如果之前已經掛載 hgfs,先取消掛載
sudo umount /mnt/hgfs
2.重新用以下命令掛載即可
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
即可成功
3.查看權限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了