Sshfs multi users

sshsshfs

I would like to use sshfs with many users.

sshfs root@192.168.56.100:/ root/

With this command I get the whole file system in the directory root/.

Is there any possibilities to change the user of a file when this user just exists on the remote machine ?

I tried:

chown myuser myfile

When I make ls -lah on the remote I get:

-rw-r--r-- 1 otheruser   root       0 Jan 11 11:03 myfile

Best Answer

The problem comes from the fact that chown will give the file to the user whose local UID belongs to myuser.

Say for example, on the local machine, you have myuser with UID 1001, but UID 1001 belongs to otheruser on the distance machine.

If you wanted to give it to myuser on the remote system, you would have to either:

  • Synchronize accounts/UID on both machines (using a centralized configuration manager can help);
  • know the distant UID of myuser (using e.g. ssh root@distant id -u myuser) and use chown with that UID.

Using the second option, you could do for example (using bash):

uid=$(ssh root@distant id -u myuser)
[[ -n $uid ]] && chown $uid. myfile || echo "No uid found. Not chowning"