Mounting a remote file system with SSHFS

If you’re working with data stored on a remote server, you might not want to (or even have the space to) copy data to your local file system when you work on it. Instead, we can use SSHFS to mount a remote file system via SSH, allowing us to read and write data on the remote file system without manually copying files.

First, if you haven’t already done so, install sshfs. It’s available for most linux distributions through your package manager (e.g. apt; dnf).

sudo apt update
sudo apt install sshfs

Next, you’ll need a local directory to mount the remote directory.

sudo mkdir /mnt/remote

The /mnt directory already exists for this purpose, but there’s no reason you have to use it. For example, if you want to allow a non-root user to use sshfs (more on this later) without write permissions in /mnt, they will need to create their own mount point.

To mount a remote directory, simply run:

sudo sshfs username@remotehost:/remote /mnt/remote

To unmount the remote filesystem:

sudo fusermount3 -u /mnt/remote

By default, sshfs can only be run as root. This complicates matters, as only the root user will be able to write the mounted file system. To get around this, we can tell sshfs to allow other users to access the mount with suitable permissions:

sudo sshfs -o allow_other,default_permissions username@remotehost:/remote /mnt/remote

You’ll also need to uncomment ‘user_allow_other’ in /etc/fuse.conf:

# Set the maximum number of FUSE mounts allowed to non-root users.                       
# The default is 1000.                                                                   
#                                                                                        
#mount_max = 1000                                                                        

# Allow non-root users to specify the 'allow_other' or 'allow_root'                      
# mount options.                                                                         
#                                                                                        
user_allow_other 

Finally, you may need to add read permissions for non-root users:

sudo chmod a+r /etc/fuse.conf

With that, you should be able to mount a remote file system and make it accessible to any user (including your own non-root account).

Author