How to mount remote file systems over SSH

From RidgeRun Developer Wiki

Overview

This guide explains how to use SSHFS to mount remote file systems over SSH. This is an alternative method to use NFS.

Introduction

Sometimes is needed to work with files that are installed on a remote system or vice-versa. It's very common to transfer files over an SSH connection, by using either SFTP or SCP. However, in some cases, it may be necessary to share entire directories, or entire filesystems, between two remote environments. An easy way to do this is by using SSHFS.

Installing SSHFS

Install sshfs package through APT.

sudo apt update
sudo apt install sshfs

How to use SSHFS

On your local system, define the path at which you wan to mount the remote file system, you can create a directory for that. Then, run the following command to mount the file system:

sshfs -o follow_symlinks <user>@<address>:<remote_path> <local_path>

To umount, run the following command:

fusermount -u <local_path>

Example

For this example, we are going to mount the home directory from an NVIDIA Jetson system.

  • Create a directory to mount the remote file system:
mkdir remote-desktop
  • Mount the Jetson home directory by using the user-name, IP address and the target path:
sshfs -o follow_symlinks nvidia@192.168.55.1:/home/nvidia/ remote-desktop
  • Check the directory corresponds to the Jetson file system:
ls remote-desktop
  • Umount filesystem
fusermount -u remote-desktop

SSHFS vs NFS

Here is a comparison between SSHFS and NFS:

Metric SSHFS NFS
Setup Simpler, just install sshfs on the client and mount nfs-kernel-server most to be installed on host server and nfs-common package is required on the client
Encryption All data shared is encrypted, disabling encryption is not allowed Data is not encrypted by default, it could be very difficult enable encryption
Performance Performance is good when encryption is needed. Compared to NFS, it's slower and CPU usage is higher because of encryption In trusted home networks NFS without encryption, it's the best choice on Linux for maximum performance
Permissions No root privileges needed to run sshfs on client mount command needs root privileges

SSHFS is easy to install, not additional configuration is needed on the server. However, all the data shared between the server/client is encrypted and decrypted, impacting the performance compared to NFS where no encryption is enabled by default. So, SSHFS it's ideal when encryption most be enabled.