I connect to my home server with ssh server, where server is configured in ~/.ssh/config as:
Host server
    HostName {server-address}
    User me
    IdentityFile ~/.ssh/id_rsa
IdentityFile is a passphrase-protected private key, so I have to enter my passphrase every time I log in.
I can locally mount the remote file system on that server with sshfs me@{server-address}:/home/me /mnt/server. Once again, I have to enter my passphrase to log in with my private key. I notice that I don't need to actually specify the key in the sshfs options - presumably ~/.ssh/id_rsa is just the default location?
Finally, to easily mount the system, I added the below line to /etc/fstab:
me@{server-address}:/home/me  /mnt/server  fuse.sshfs  IdentityFile=/home/me/.ssh/id_rsa,defaults,noauto 0 0
And this lets me simply run mount /mnt/server to mount the filesystem - and of course, I'm asked for my passphrase.
Note that I had added the noauto option so that it wouldn't be mounted on boot, as I was worried the system would hang if it couldn't mount the filesystem without the passphrase.
Is my suspicion right here? Will the system fail to boot if it tried to mount the server filesystem, but didn't get the passphrase? Is there a way that I can supply the passphrase to /etc/fstab / the mount command, so that it will be able to boot the filesystem on boot?
In ubuntu 20.04 server, this worked for me (step by step)
install sshfs
sudo apt-get update
sudo apt-get install sshfs
i created the key pair (without passphare), and copy it to remote server
ssh-keygen
ssh-copy-id REMOTE_USER@REMOTE_SERVER
add this line in /etc/fstab (thanks to @Sealad), replace all uppercase
REMOTE_USER@REMOTE_SERVER:/home/me  /mnt/server    fuse.sshfs  defaults,_netdev,allow_other,default_permissions,identityfile=/home/USER/.ssh/id_rsa,uid=UID,gid=GID    0   0
use this to get UID and GID
id -u USER
id -g USER
and do this only once (it should ask you for remote password)
sudo mount -a
reboot your system to check
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With