Cloud computing

Access Remote File Systems Over SSH with SSHFS

Hardware failures, theft, user error, natural disasters. There are always risks with storing your data however much care you take. Fortunately many of these risks can be mitigated with a backup and disaster recovery plan. An important element to this plan is to use a remote backup solution.

Readers who have been following my series of reviews on free and open source backup software will have noticed that many of the programs lack any specific functionality for cloud support. However, there are a number of options available to replicate this functionality for yourself.

One solution is to use a regular virtual private server or a dedicated server. Combine that with SSHFS, a file system in user space (FUSE) that uses the SSH File Transfer Protocol (SFTP) to mount a remote file system. SSHFS lets you interact with directories and files located on a remote server or workstation over a normal ssh connection

Two Linux machines are configured to allow SSH access between them. One of these can be a local machine rather than a remote server.

1. Install SSHFS

SSHFS is available for the majority of Linux distributions including Ubuntu and Manjaro.

On Ubuntu, we can install the software using apt.

First, issue the command $ sudo apt update && sudo apt upgrade to refresh your package sources and update the system. Then issue the command:

$ sudo apt install sshfs

Installing sshfs in Ubuntu

On Manjaro, we’ll use yay to first update our system. Issue the command $ yay and then install SSHFS with the command:

$ yay -S sshfs

Installing SSHFS in Manjaro

2. Mount the Remote Filesystem

We’ll create a directory on our local machine so that we can mount our remote filesystem. Both Ubuntu and Manjaro have a directory named /mnt. So we’ll create a subdirectory within /mnt. We’re using a dedicated server from ZAP-Hosting, so we’ll create a mount directory called /mnt/zap with the command:

$ sudo mkdir /mnt/zap

make directory

Note that the zap directory is owned by root. We’ll make the current user the owner of /mnt with the command:

$ sudo chown $USER /mnt/zap ; sudo chgrp $USER /mnt/zap

change directory permissions

We can now proceed and mount the remote directory with SSHFS. Our username on both the local and remote machine is sde. We’ll substitute that with $USER in the command below.

$ sudo sshfs -o allow_other,default_permissions $USER@your_remote_server:/home/$USER /mnt/zap

-o default_permissions enables local permission checking.

The sshfs command only mounts a remote disk for the current session. If the remote machine or local machine is powered off or rebooted, we need to use the same process to mount it again.

We can unmount the remote directory with the command:

$ sudo umount /mnt/zap

3. Permanently Mounting the Remote Filesystem

It’s a bit more complicated to permanently mount the remote filesystem. We use key-based authentication to connect to our remote system. SSH public key authentication relies on asymmetric cryptographic algorithms that generate a pair of separate keys (a key pair), one “private” and the other “public”. You keep the private key a secret and store it on the computer you use to connect to the remote system. Both our local and remote system has ssh installed.

The sshfs command can also be used in the client system’s /etc/fstab file to automatically mount the remote file system. Use the normal fstab syntax, including any options required, and use sshfs in place of the file system type.

Permanent SSHFS mounts are not often popular. The nature of SSH connections and SSHFS means that it is usually best suited to temporary, one-off solutions.

4. Summary

SSHFS is simple to setup and can be used by non-privileged users on the local machine. Given that your backup data is stored on a remote machine we strongly recommend you use backup software that offers encryption.

Even if you’re not looking for a remote backup solution, SSHFS is an extremely useful way of accessing files and directories stored on a remote server.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Please read our Comment FAQ before posting a comment.

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mike
Mike
5 months ago

Decent article **however** the main point of the article looks like you accidentally left out the mount command! An important typo you should fix!

Tomas
Tomas
5 months ago

What filesystem type does sshfs give?