How to change the owner on a shared hgfs folder

Let’s assume you want to change the owner of your shared folder to the user www-data and the group www-data

  • we use VMWare Fusion
  • VMWare Tools must be installed and updated
  • tested on Ubuntu Server 14.10 LTS and 15.04

1. create file /bin/remount_hgfs

1.1 become root on your system

sudo su

1.1 create the file with touch

touch /bin/remount_hgfs

1.2 make it executable

chmod a+x /bin/remount_hgfs

1.3 add the following 3 lines to the file

!/bin/sh -e
umount /mnt/hgfs
mount /mnt/hgfs

echo '#!/bin/sh -e' >> /bin/remount_hgfs
echo 'umount /mnt/hgfs' >> /bin/remount_hgfs
echo 'mount /mnt/hgfs' >> /bin/remount_hgfs

2. update your fstab file

i assume the uid and the gid of the user www-data on your system is 33, which is default on most Debian based Systems. You can verify that by doing:

id www-data

If you want to mount as a different user you can find out the same way. If the id is different please modifiy the value of the next command.

2.1 add the following line to your fstab file

.host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=33,gid=33,nobootwait 0 0

echo '.host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=33,gid=33,nobootwait 0 0' >> /etc/fstab

3. make sure the remount_hgfs gets executed when the system starts

3.1 add the following line to /etc/rc.local, before the exit

sh /bin/remount_hgfs

line=`wc -l /etc/rc.local | cut -f1 -d' '`; sed -i "${line}ish /bin/remount_hgfs" /etc/rc.local

4. reboot you VM

reboot

Now if you do „ls -l /mnt/hgfs“ you should see that the folder belongs to www-data:www-data

For those who trust me, you can do all commands at once 😉

sudo su
touch /bin/remount_hgfs
chmod a+x /bin/remount_hgfs
echo '#!/bin/sh -e' >> /bin/remount_hgfs
echo 'umount /mnt/hgfs' >> /bin/remount_hgfs
echo 'mount /mnt/hgfs' >> /bin/remount_hgfs
echo '.host:/ /mnt/hgfs vmhgfs rw,ttl=1,uid=33,gid=33,nobootwait 0 0' >> /etc/fstab
line=`wc -l /etc/rc.local | cut -f1 -d' '`; sed -i "${line}ish /bin/remount_hgfs" /etc/rc.local
reboot

That’s it 😉

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *