Basically, it works like this (as root or use sudo ): sshfs -o default_permissions,nonempty,IdentityFile=/home/USER/.ssh/id_rsa SRVUSER@SERVER :PATH /mnt/mountpoint
Replace USER with the user located in the authorized_keys file of the server, SERVER with the server name (or IP, like 192.168.0.11), SRVUSER with the user on the server (for example, root, which is not recommended, but is possible and sometimes necessary; for this, configure it correctly /etc/ssh/sshd_config on the server, i.e. the PermitRootLogin and PasswordAuthentication directives). Also replace /mnt/mountpoint accordingly.
The -o nonempty allows -o nonempty to mount / mnt / mountpoint when this directory is not empty. I have to use this since I store the .unmounted file in this directory to see if it is mounted or not, so if test -e /mnt/mountpoint/.unmounted returns successfully (i.e. the .unmounts file exists in / mnt / mountpoint), it is not mounted.
Real example:
- server name "homeserver"
- mount / home directory on the server
- my mount point on the local system is / mnt / homeserver
- user "steve" has a private key
ssh root@homeserver how user Steve worked .
sshfs -o default_permissions,nonempty,IdentityFile=/home/steve/.ssh/id_rsa root@homeserver :/home /mnt/homeserver (as root)
This did not work , I received an error message: read: Connection reset by peer
Solution: Get more verbose output by adding -o debug .
And suddenly it is much easier to fix. Since sshd keys have been recreated since the last session, but /root/.ssh/known_hosts on the local system still have old keys - it does not work. In my case, the solution was to simply delete the line starting with homeserver from /root/.ssh/known_hosts using an editor (e.g. nano ). Now sshfs installation works. When connecting for the first time, the new key must be confirmed:
By the way, this is the line in /etc/fstab :
root@homeserver :/home /mnt/homeserver fuse.sshfs noauto,nonempty,default_permissions,IdentityFile=/home/steve/.ssh/id_rsa 0 0
So even if it's something else, try -o debug first. This will help to find a mistake.