79

I am using sshfs to mount a folder with some python projects over ssh to my ~/ directory.

$ mkdir -p ~/mount/my-projects
$ sshfs [email protected]:/home/user/my-projects ~/mount/my-projects

I can perform most commands as could be expected:

$ ls ~/mount/my-projects
some-python-project

But I if I try to do anything with sudo, it fails with permission denied:

$ sudo ls ~/mount/my-projects
ls: cannot access /home/user/mount/my-projects: Permission denied

What I'm actually trying to accomplish is to test a python package installation script on my local machine:

$ cd ~/mount/my-projects/some-python-project
$ sudo python setup.py install

3 Answers 3

128

I believe you need use the allow_other option to sshfs. In order to do this, you should call it with sudo, as follows:-

sudo sshfs -o allow_other user@myserver:/home/user/myprojects ~/mount/myprojects

Without this option, only the user who ran sshfs can access the mount. This is a fuse restriction. More info is available by typing man fuse.

You should also note that (on Ubuntu at least) you need to be a member of the 'fuse' group, otherwise the command above will complain about not being able to access /etc/fuse.conf when ran without 'sudo'.

2
  • 2
    Good first answer!
    – slm
    Commented Dec 28, 2012 at 15:31
  • 20
    See also the allow_root option to allow root only. Please note however that those options are restricted to root by default unless you add a user_allow_other line to /etc/fuse.conf. Commented Dec 28, 2012 at 15:55
13

sshfs is a userland process, so there is no need to run it with sudo.

If you do run it as sudo and use SSH key authentication, then the key will be searched under /root/.ssh and not under your user's /home/myuser/.ssh.

The same applies to ~/.ssh/config file which sshfs is capable of using.

If you have a ~/.ssh/config like:

Host remotehost
    HostName 111.22.33.44
    User root
    Port 1234
    IdentityFile ~/.ssh/id_rsa

then you could mount your remote host as a normal user with:

sshfs remotehost: local_dir

To run under root you could append -o IdentityFile /home/myuser/.ssh/id_rsa to the 'raw' sshfs command, or to create /root/.ssh/config with the full path to your user's SSH key:

Host remotehost
    HostName 111.22.33.44
    User root
    Port 1234
    IdentityFile /home/myuser/.ssh/id_rsa

Now sshfs remotehost: local_dir will also work under root.

With your .ssh/config in place you can copy entire folders between the hosts with (remote to local) scp -r remotehost:remotedir localdir or (local to remote) scp -r localdir remotehost:remotedir, so for a single one-off operation, you might not even need sshfs.

If you use a relative remote path as in remotehost:remotedir then remotedir will be relative to the user's home folder, i.e. remotehost:remotedir is equivalent to remotehost:/home/myuser/remotedir

1
  • OP does mount the filesystem as normal user. The problem arises with the need to access files on that filesystem from a root context.
    – misiu_mp
    Commented Feb 25, 2020 at 3:58
8

What solved the problem for me was adding the allow_other option to the command like so:

$ sshfs -o allow_other [email protected]:/home/user/my-projects ~/mount/my-projects

then you might get the error:

option allow_other only allowed if 'user_allow_other' is set in /etc/fuse.conf to solve that head to /etc/fuse.conf with your favorite text editor and uncomment (delete the # behind) user_allow_other

If that solved the problem and you could run sshfs successfully, great! If not you should try adding your user to the fuse group by this command:

$ sudo usermod -a -G fuse mark

and if it results in error saying fuse group doesn't exist you can easily create that group by:

$ sudo groupadd fuse
2
  • sudo groupadd fuse, not mynewgroup, then either run the usermod again or edit /etc/group and add the user's name on the end of the fuse line
    – pauljohn32
    Commented Mar 19, 2020 at 23:14
  • Also, sudo usermod -a -G fuse mark, not mark fuse
    – Harm
    Commented Jan 20, 2021 at 10:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .