21

So I am trying to mount a folder from another computer in my LAN, and I am able to ssh without any issues. But, I am unable to make any changes when I access the mounted folder.

This is what I have done so far:

Install:

$sudo apt-get install sshfs
$sudo modprobe fuse
$sudo adduser <username> fuse
$sudo chown root:fuse /dev/fuse
$sudo chmod +x /dev/fuse
$mkdir ~/remoteserv

And when I access the remote folder via sshfs:

$sshfs -o idmap=user <username>@<ipaddress>:/home/user ~/remoteserv

The output of becomes:

$~/remoteserv$ ls -l
total 60
drwxr-xr-x 1 <notmyusername> <notmyusername> 4096 2012-04-13 21:54 Desktop
drwxr-xr-x 1 <notmyusername> <notmyusername> 4096 2012-04-10 13:05 Documents
drwxr-xr-x 1 <notmyusername> <notmyusername> 4096 2012-04-17 19:06 Downloads
drwxr-xr-x 1 <notmyusername> <notmyusername> 4096 2012-04-13 21:55 Music
drwxr-xr-x 1 <notmyusername> <notmyusername> 4096 2012-04-03 15:07 Pictures
... more of the same

I am unable to access any of the files properly because sshfs is mounting the files under my wife's username! I have no idea why, and I feel like I have made a large mistake somewhere. Is there some configuration file which I need to tweak somewhere? I can't seem to find anything on the manpage :/

I even tried an -o allow_other option when I mounted, but it still mounted it under my wife's username! What is going on?

Robert
  • 311
  • 1
  • 2
  • 6
  • This thread is quite old, but: did the answer below help you? – rexford Apr 05 '16 at 08:06
  • @rexford Wow, I don't even remember what I ended up doing this was so long ago. I think I ended up using a python SimpleHTTPServer like this https://mohitishere.wordpress.com/2012/10/24/instant-lan-file-sharing-with-python-simplehttpserver/ In the desired directory: `python -m SimpleHTTPServer` Then visit : http://localhost:8000/ – Robert Apr 09 '16 at 01:15

2 Answers2

27

It's worth a try to explicitly set the UID/GID. This could be done, for example, using the sshfs options:

uid=$(id -u),gid=$(id -g)

or

uid=$(id -u someuser),gid=$(id -g somegroup)

See https://wiki.archlinux.org/index.php/SSHFS#Secure_user_access for more details.

fosslinux
  • 3,771
  • 4
  • 28
  • 46
tohuwawohu
  • 7,282
  • 5
  • 27
  • 33
  • This does not seem to match what the documentation says, neither does it work for me. -o idmap=username leads to an error and according to the docs, idmap can only be "none", "user" or "file" anyway. (on the other hand, the uid= and gid= options do have the desired effect when used alone) – Nobody Nov 29 '16 at 17:55
  • @Nobody: Seems you're right - i can't remember if it worked as described over four years ago. TY for your comment! – tohuwawohu Dec 02 '16 at 10:18
  • Thanks. This is also related: http://unix.stackexchange.com/questions/17402/why-does-root-get-permission-denied-when-accessing-fuse-directory (maybe even a cross site duplicate) – Nobody Dec 02 '16 at 10:55
  • In my case sshfs was using a readonly user for cockpit (1001:1001). I could have get compromised… Do we have any idea on why sshfs behave this way ? – ethicnology Jul 19 '23 at 13:36
9

The complete command is

sshfs \
-o uid=`id -u username` \
-o gid=`id -g username` \
-o allow_other \
[email protected]:/target/folder \
/local/folder

it maps username's user_id and group_id to the mountpoint (so the mountpoint looks like that user's own). The allow_other allows others to use this mountpoint which is good if the root mounts the folder for someone else.

Alternatively you can use -o allow_root to let root there too.

andrej
  • 396
  • 3
  • 7
  • 1
    This answer is incomplete. Who are you replying to? Please note that this is a Q&A site, not a discussion forum. Please try to compose your answers in a way that it answers the question without needing to read another post. – Nmath Nov 13 '20 at 03:23
  • 2
    This worked for me and is really just a clearer and more complete version of the answer from tohuwawohu that I didn't understand at first. – Roger Krueger Dec 05 '22 at 02:31
  • This almost worked. I get the files/directories in the mount folder mapped to my user, but still get a permission denied when trying to create a file... – borizzzzz Jun 21 '23 at 08:35
  • @borizzzzz maybe the target_user can not create file on the target.server in /target/folder – andrej Jun 22 '23 at 09:44