Using SSHFS to securely mount remote file systems

cloud-storage

Securely mount remote file systems easily with sshfs. Edit remote files in your favourite GUI editor locally as if they were present on your own box.

Reading time:
2 min

SSH filesystem

If you'd like to mount a remote file system but don't want the hassle of setting up something like NFS you should try out sshfs. This really handy program uses ssh for it's underlying security and authentication (and uses the sftp subsystem on the remote machine). It will allow you to securely manipulate (over an encrypted connection) the remote files as if they were local.

Now you can edit remote files in your local GUI editor as if they were present locally (as long as you have the correct permissions to access the remote files!).

Another example of how this can be really handy is: say you want to run a log file analysis program, but you don't have permission to run such a program on the remote machine where the log file lives. As long as you have normal read permissions for the log file, you can use sshfs to mount the remote location then just run the analysis program locally which can now analyse the remote log file as it changes.

Note that the ssh daemon must already be installed and running on the remote side in order for sshfs to work (this is because sshfs is built on top of ssh).

Installing SSHFS

To install sshfs, simply run the following:

sudo apt-get install sshfs

Setting up SSHFS

Create a directory to use as the mount point e.g:

mkdir mpoint

Mount the directory using the syntax:

sshfs user@ip-address:/path/to/remote/dir/ mpoint

For example if the ip address of the remote machine is 192.168.0.7, to mount /root/mystuff on the remote machine as root, run this command on your local box:

sshfs [email protected]:/root/mystuff/ mpoint

You'll be prompted for a password as per ssh. That's all that's required. Now, if you cd to the directory mpoint, and run the ls command, you'll see the files from the remote filesystem appear on yours.

Bear in mind that if you've set up an ssh key pair, no password will be required.

Also, sshfs will make use of connection sharing if you've set that up.

Unmounting

When you're finished, you'll want to unmount the remote filesystem. To do this, simply run:

fusermount -u mpoint

For further information about sshfs, take a look at the man page.

Thanks to Miklos Szeredi for writing sshfs.

Thank you for reading this article.
Please share if you liked it.