sshfs with fstab: connection reset by peer
The problem you are experiencing is that your normal user has a correct setup for your identity file, while the root user has no idea what ssh key to use.
You can fix this by telling fstab what identity file/ssh key to use while trying to connect:
sshfs#user@host:/mnt/whatever/ /mnt/whatever/ fuse user,_netdev,reconnect,uid=1000,gid=1000,IdentityFile=/home/USER/.ssh/KEYFILE,idmap=user,allow_other 0 2
To get real debug output you need to add both sshfs_debug
and debug
options to the mount:
sshfs#mynickname@my-PC:/a_folder /media/a_folder fuse defaults,idmap=user,_netdev,debug,sshfs_debug 0 0
With this you will get a lot of debug info to help you:
$ sudo mount -a
SSHFS version 2.5
FUSE library version: 2.9.2
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
executing <ssh> <-x> <-a> <-oClearAllForwardings=yes> <-2> <user@box> <-s> <sftp>
user@box's password:
Server version: 3
Extension: [email protected] <1>
Extension: [email protected] <2>
Extension: [email protected] <2>
Extension: [email protected] <1>
Extension: [email protected] <1>
unique: 1, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0
INIT: 7.22
flags=0x0000f7fb
max_readahead=0x00020000
remote_uid = 1001
INIT: 7.19
flags=0x00000011
max_readahead=0x00020000
max_write=0x00020000
max_background=0
congestion_threshold=0
unique: 1, success, outsize: 40
unique: 2, opcode: STATFS (17), nodeid: 1, insize: 40, pid: 2771
unique: 3, opcode: LOOKUP (1), nodeid: 1, insize: 47, pid: 3371
In my case I discovered that my machine was only listed in .ssh/config
, so it was unresolvable for root.
And BTW, you need to set uid and gid, since idmap=user
only seems to work for the current user, which is root in this case.
This problem can also occur when the host key of ssh changes.
Try to connect to the server via ssh (e.g. ssh username@hostIP
). If the following error appears:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Follow the instructions in the error message to delete the old key and try to connect again via ssh. If the error does not appear any more, the sshfs connection should work.