sshsshfsfstab

SSHFS works on command line but not within fstab


I am trying to connect two servers with SSHFS.

As root, when launching the command sshfs myuser@ip_adress:/some/dir /other/dir -o idmap=user,identityfile=/home/myuser/.ssh/id_rsa, everything works.

However, when I set this SSHFS configuration in /etc/fstab and running mount -a, it hangs. The line in /etc/fstab is:

myuser@ip_adress:/some/dir /other/dir  fuse.sshfs defaults,_netdev,IdentityFile=/home/myuser/.ssh/id_rsa 0 0

I have tried a lot of options but so far, nothing works.

By adding ssh_command=ssh\040-vv,sshfs_debug,debug in the /etc/fstab options and running mount -av, I have the following output:

executing <ssh> <-vvv> <-x> <-a> <-oClearAllForwardings=yes> <-oidentityfile=/home/myuser/.ssh/id_rsa> <-2> <myuser@ip_adress> <-s> <sftp>
OpenSSH_8.4p1 Debian-5, OpenSSL 1.1.1k  25 Mar 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolve_canonicalize: hostname ip_address is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/root/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/root/.ssh/known_hosts2'
debug2: ssh_connect_direct
debug1: Connecting to ip_address [ip_address] port 22.
debug1: Connection established.

I don't see why the SSH connection is hanging at this point.

Do you know what is the issue?

Thank you


Solution

  • So I found the issue: I was trying to mount the .ssh folder (which has the key to connect to the remote server).

    I don't know exactly why it was working on the command line and not through fstab (may be something with the SSH agent) but mounting the folder used to connect to SSHFS caused the issue. I moved the SSH keys to another directory and then it worked like a charm.