➥ sshfs and map folder with a proxy

In many cases it can become cumbersome to transfer files to and from a droplet. Imagine a development usage scenario where you are coding apps remotely and find yourself uploading a script repeatedly to your virtual server to test. This can become quite a hassle in a very short period of time. Luckily there is a way to mount your VPS file system to your local computer so you can make changes on the fly and treat your droplet as local storage. In this article, we will show you how to do exactly that.

Configure ssh key-based authentication
Generate key pair on the local host with your username.

$ cd /home/yourprofile/.ssh
$ ssh-keygen -t rsa -b 4096

Accept all sugestions with enter key.

Copy public key to the remote host:

$ ssh-copy-id -i .ssh/id_rsa.pub user@host

Install sshfs

$ sudo apt install sshfs

Mount remote directory

$ mkdir /home/yourUserName/remotefoldername
$ chmod 777 /home/yourUserName/remotefoldername
$ sshfs user@host:/remote_directory /local_directory -o "ProxyCommand=nc -X connect -x %h %p"

Don't try to add remote fs to /etc/fstab
Or don't try to mount shares via /etc/rc.local .
In both cases it won't work as the network is not available when init reads /etc/fstab.

Install AutoFS

$ sudo apt install autofs

Edit /etc/auto.master

Comment out the following lines


Add a new line

/- /etc/auto.sshfs --timeout=30

Save and quit

Edit /etc/auto.sshfs

Add a new line

/local_directory -fstype=fuse,allow_other,IdentityFile=/local_private_key :sshfs\#user@remote_host\:/remote_directory

Remote user name is obligatory.

Save and quit

Start autofs in debug mode

$ sudo service autofs stop
$ sudo automount -vf

Observe logs of the remote ssh server

$ ssh user@remote_server
$ sudo tailf /var/log/secure

Check content of the local directory

You should see contents of the remote directory

Start autofs in normal mode

Stop AutoFS running in debug mode with CTRL-C .

Start AutoFS in normal mode

$ sudo service autofs start