sshfs mount, sudo gets permission denied
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'.
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 needsshfs
.If you use a relative remote path as in
remotehost:remotedir
thenremotedir
will be relative to the user's home folder, i.e.remotehost:remotedir
is equivalent toremotehost:/home/myuser/remotedir
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