Easy Steps to SSHFS Automatic Remote File System Mount Linux

Quick and easy, step-by-step instructions for Linux, on setting up an automatic on demand mount of a remote system – accessible via SSH.

SSHFS Mount

First, by setting up RSA Key Authentication between the two systems that eliminates the need for a manual password entry. And then, by setting up a local directory for mounting the file system with Sshfs. The remote system will be auto-mounted only “on demand”, when the mount directory is being accessed. Not on boot.

Stage 1: RSA Key Authentication with SSH

— Make sure you have Sshfs installed.

apt-get install sshfs

— Run below command in console as normal user & hit enter for all the questions, (file path, no password..).

ssh-keygen

— Copy newly created public key to remote host root.

scp .ssh/id_rsa.pub user@remotehost.com:local-host.ssh

— Log in to remote file system using conventional method.

ssh user@remotehost.com

— Create known_hosts file with contents of the public key.

cat local-host.ssh >> .ssh/authorized_keys

— Fix file permissions (important..).

chmod 744 .ssh
chmod 644 .ssh/authorized_keys
chmod 755 $HOME

— Log out from system and test if you can connect to the remote system via SSH without a password.

Stage 2: Creating Sshfs Mount Point

— Create a mount directory, mountable by root.

sudo mkdir /mnt/remote

— Edit fstab with connection details to remote host and path to user’s private key.

sudo nano /etc/fstab

user@remotehost.com:/remote/directory /mnt/remote fuse.sshfs noauto,x-systemd.automount,_netdev,users,idmap=user,IdentityFile=/home/[USER]/.ssh/id_rsa,allow_other,reconnect 0 0

— Mount file system or reboot.

sudo mount /mnt/remote

These steps for this “how to” were tested using Ubuntu. Kernel 4.1x.

Questions & comments this way! And please..
Share this post if humanly possible. Thanks, David.

Leave a Comment