I want to sshfs from my Linux machine (Ubuntu 18.04.2 LTS) to my MacBook. I could do it at command line with
sshfs jczhang@10.0.2.2:/Users/jczhang/mysharedfolder /home/jczhang/mysharedfolder
It worked perfectly. Since I wanted to mount the shared folder automatically at boot time, I put this in /etc/fstab.
jczhang@10.0.2.2:/Users/jczhang/mysharedfolder /home/jczhang/mysharedfolder fuse.sshfs delay_connect,_netdev,user,uid=1000,gid=1000,IdentityFile=/home/jczhang/.ssh/id_rsa,allow_other 0 0
Here, 1000 is my uid and gid in Linux. After reboot, I found the directory was mounted but I could not access the directory.
ls -l
d????????? ? ? ? ? ? mysharedfolder/
cd mysharedfolder
-bash: cd: mysharedfolder: Input/output error
mount status had
jczhang@10.0.2.2:/Users/jczhang/mysharedfolder on /home/jczhang/mysharedfolder type fuse.sshfs (rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,allow_other,_netdev,user)I did not know why sshfs kept using user_id=0,group_id=0. I tried different combinations of uid=1000,gid=1000 and idmap=user. None worked. I umounted the shared folder and did "mount -a". It still did not solve the problem.
I used the default SSHFS version 2.10. Later, I upgraded it to version 3.5.2. Nothing changed.
Does anyone know a solution? Thanks.
UPDATE:
This problem drove me mad. Since this shared folder is for my personal use and sshfs works at command line, I find a workaround. In .bashrc, I putif ! [ -d /home/jczhang/mysharedfolder/flagfile ]; then sshfs jczhang@10.0.2.2:/Users/jczhang/mysharedfolder /home/jczhang/mysharedfolder -o idmap=user,uid=1000,gid=1000
fiflagfile is a file to tell whether the folder is already mounted.
Every (first) time I login to Linux, the folder is automatically mounted for me.
It works great!
32 Answers
I had this same problem. Problem turned out to be that the remote was not present in the local machine root's known_hosts file. Simply doing:
sudo mount /path/to/mountwill cause sshfs to prompt for addition of remote into root's known_hosts file - so if you choose yes at the prompt, it should be done.
Note the sudo. mount without sudo will mount it successfully, but will add the remote to the user's known_hosts file instead of the root's. fstab entries are mounted by root, so if you've not added the remote to the root's known_hosts, it won't find it and the mount will be incomplete, and results in the input/output error.
I have this exact setup working:
My OS as 18.04.2:
] lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionicMy SSHFS version:
] sshfs -V
SSHFS version 2.8
FUSE library version: 2.9.7
fusermount version: 2.9.7
using FUSE kernel interface version 7.19Creating the base:
] sudo mkdir /path/to/mount
] sudo chown $USER: /path/to/mount
] sudo nano /etc/fstab
] ssh REMOTEUSER@HOSTNAME touch /path/to/share/testfile/etc/fstab entry: (you can remove the port entry)
REMOTEUSER@HOSTNAME:/path/to/share /path/to/mount fuse.sshfs port=PORT,_netdev,follow_symlinks,identityfile=/home/LOCALUSER/.ssh/RSAKEY,allow_other,uid=1000,gid=1000 0 0Testing mount:
] sudo mount -a
] mount | grep HOSTNAME
REMOTEUSER@HOSTNAME:/path/to/share on /path/to/mount type fuse.sshfs (rw,relatime,user_id=0,group_id=0,allow_other,_netdev)
] ls -l /path/to/
...
drwxr-xr-x 1 LOCALUSER LOCALGROUP 4096 Jun 28 09:20 mount/
...
] ls -l /path/to/mount/testfile
-rw-rw-r-- 1 samh samh 0 Jun 28 10:45 /path/to/mount/testfile