3

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
Bart De Vos
  • 17,911
  • 6
  • 63
  • 82
Charles
  • 185
  • 2
  • 8

3 Answers3

2

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"
raphink
  • 11,987
  • 6
  • 37
  • 48
  • I thought about your second solution for 20 minutes under my shower :p Thanks it works very well :) – Charles Jan 11 '12 at 10:50
2

Look for the posixovl filing system.

Assuming ~/REMOTESITE is an sshfs mount of the remote system:

/usr/local/sbin/mount.posixovl -F -S ~/REMOTESITE/user-backups /REMOTESITE -- -o allow_other

(I'm not sure if the 'allow_other' is strictly needed but it doesn't hurt.)

The remote files remain owned by whoever is logged in to the remote account but to the local system they appear to be owned by local users.

(You might also want to layer encfs over this so you don't need to trust the remote site)

Graham

0

No you cannot do that. All the files on remote system are accessed as the "user" that is used while mounting it. In your case it is root .

daya
  • 271
  • 1
  • 6