What do you think? Discuss, post comments, or ask questions at the end of this article [More about me]

Skip to end of metadata
Go to start of metadata

Often you need to edit/modify a file on a remote server.  Generally you can simply SSH into said server (assuming you have SSH access) and use a text editor (there can be only one: vim). 

However, what happens when you need to edit said file with something else... say, an application that doesn't naturally run on the CLI?  You might say "copy it to your local machine, edit and copy back"... that's a pain but could work.  However, what happens if the file is in use (say by a web application) and you can't mv (or copy over) it?

Here's an actual use case: I'm a fan of isso, a simple commenting server app to integrate public commenting in blogs, web applications etc (see the end of this article as it uses isso for comments.  Also see my article setting up isso here).

isso uses an sqlite backend (e.g. all data kept on server in a single sqlite file).  On a few occasions I've needed to access and modify some of my post comments.  Since it's sqlite, I could use something like db DB Browser for SQLite to open the file and make then write changes without needing to copy the file, edit, and then copy back... however, it's on my server... which brings us to SSHFS.

With SSHFS, I could mount the remote server folder locally on my main machine (which is running Linux of course (tongue)) then use DB Browser for SQLite to open the sqlite db, modify and write changes, then umount.

Guide

Install SSHFS

You might already have SSHFS installed on your distro.  If not, install from your package manager.  If you're using Debian or Ubuntu Server, you would do a

sudo apt install sshfs

Mounting a remote folder

I assume you have SSH configured and you can SSH into your server (if not see here).

If you can SSH into your server with a simple

ssh <user>@<server-ip-address>

then you can mount a remote server folder locally with:

sshfs <user>@<server-ip-address>:<server-full-path-of-folder> <location-of-where-to-mount-locally>

For example, to mount my "isso" home folder on my server to /home/user/isso I would do

mkdir /home/user/isso
sshfs user@58.96.123.236:/home/isso /home/user/isso

If you have already created your local mount point (folder) then you don't need to run the mkdir command above every time.

Use a specific ssh .pem file

you can also use a specific ssh .pem file (key) with sshfs.  You might want/need to do this if you have multiple ssh private keys for example.  The command to do so is similar to above

sshfs -o IdentityFile=<pem-file-path> <user>@<server-ip-address>:<server-full-path-of-folder> <location-of-where-to-mount-locally>

For example

sshfs -o IdentityFile=/home/user/.ssh/other-key.pem jay@58.96.123.236:/home/isso /home/user/isso

Unmounting

You can unmount your sshfs mount by using umount 

umount ~/home/user/isso

References

  1. https://computingforgeeks.com/installing-using-sshfs-ubuntu-fedora-arch-centos/