45

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

$ mkdir -p ~/mount/my-projects
$ sshfs user@example.com:/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
81

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
    Good first answer! – slm Dec 28 '12 at 15:31
  • 11
    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. – Stéphane Chazelas Dec 28 '12 at 15:55
  • Helped me out of a jam, thank you for this! – Oldskool Jun 25 '14 at 14:30
3

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

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

$ sshfs -o allow_other user@example.com:/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:

$ usermod -a -G mark fuse

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

$ sudo groupadd mynewgroup

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.