SSHFS, File Sharing made easy

LXD

SSHFS remote file server

by Craig Miller

In this modern world, a computer is rarely an island. There is often a file(s) one wants to use from a remote system. Sure, you can use the web to download remote files using a browser, but that is a one-way trip (download only). What if you want to share files (download and upload) transparently as if it were just an extension to the filesystem itself?

Early Windows, Mac & Unix had their respective file sharing protocols, but for the most part they didn't share between OSs. Fast forward to the early 2000s and Macs figured out that having SMB (Windows file sharing) support helped sell Macs into Windows shops. Linux used NFS (Network File System) natively, but could also speak SMB, and AFP (Apple Filing Protocol) with some configuration.

But all of that took time, and for the most part was still silo-ed by OS. SSHFS is an extension to SSH created in 2005.

Why do we need it?

SSHFS provides transparent Remote File system access with minimal configuration and setup.

SSHFS breaks the Silos of proprietary OS file sharing. Since it is an extension of SSH, it has been implemented on nearly every OS.

Easier to setup and use than Samba

Since it is an extension to SSH, it is much easier to install/setup than, say, Samba. There are no additional accounts to configure, no additional daemons to be run, and it utilizes the encrypted transport of SSH, so it is secure.

What is SSHFS?

SSHFS is a network file sharing client, which communicates with an existing SSH server on a remote host (such as a Raspberry Pi). It uses FUSE (File System in Userspace) which allows non-privileged users create their own file systems without kernel permissions.

FUSE

FUSE was implemented as part of the Virtual File System (VFS) in the Linux 2.6.14 kernel, with libfuse being the user space component.

FUSE

The FUSE architecture allows other file system support without requiring kernel support.

What is needed to run SSHFS?

A client (SSHFS) and a server (typically sshd with SFTP support). That's it!

If you are accessing a remote server via SSH, then no additional ports on the firewall are required to run SSHFS.

What Platforms are supported by SSHFS?

Just about everything except your iPhone. And even that is supported if you are comfortable jail breaking your iPhone first.

Installation on Linux

SSHFS is a FUSE filesystem client, that is available on most distributions. Use your package manager to install it.

Debian/Ubuntu

sudo apt-get install sshfs

Redhat/CentOS

sudo dnf install sshfs

Alpine

sudo apk add sshfs

Arch/Artix

sudo pacman -S sshfs

OpenWrt

opkg update
opkg install sshfs

FreeBSD

# install the package
pkg install fusefs-sshfs
# load kernel module for FUSE
kldload fuse

Installation on ChromeOS

There is a native ChromeOS application, SecureShellApp, on Google's WebStore. Not only is it a ssh client, but also a SSHFS client. Mounted remote_hosts can be managed by the ChromeOS Files App.

Modern Chromebooks not only run ChromeOS, but also support Android apps, as well as Linux, via LXD (Linux Containers). Both support SSHFS.

Installation on Android

Android has an app for that, EasySSHFS. It is available on Google Playstore.

Installation on Windows

SSHFS is also supported on Windows 10, via WinFCP and SSHFS-Win. There is an excellent Install Tutorial by Zora Lab.

They also have a good how-to on using SSHFS-Win.

Installation on MacOS X

MacOS X, being a BSD-based system, should make it easy to install. Like Windows, one must install Fuse for MacOS X before installing SSHFS. It is supported on Intel-based Macs 10.15 and later. Given some time, I am sure it will also support Arm-based Macs as well.


1. Hands On - Install SSHFS

Refer to the above information for your OS/Platform.

Discuss the following:












Mounting a remote file system with SSHFS

Since the FUSE system does not require root privilege, it is possible to mount a remote file system as a regular user. In Linux, the command to mount is (1):

sshfs remote_user@remote_host:path local_path

cd
# create a mount point
mkdir Docs
# mount the remote host on the mount point
sshfs demo@netsig.makiki.ca:Docs Docs/

It is good hygiene to unmount remote drives that are no longer in use. In Linux this is done with the fusermount command.

fusermount -u Docs/

Use the -d option to enable debug, and see more of what is going on with sshfs.


2. Hands On - Mount a remote file system with SSHFS

Now that you have SSHFS installed, mount a remote file system (e.g. your local Raspberry Pi). Use the Tutorials (above) if you aren't using Linux.

Discuss the following:












Advantages

Besides the advantages of ease of setup, and cross-platform compatibility, there are additional benefits to using SSHFS:

Disadvantages

But like all things, there are some downsides as well:

Go forth, and remote mount

SSHFS is an excellent solution to file sharing, which is much easier to setup than other network file systems. In addition, it has cross-platform compatibility, while using an encrypted stream, thanks to its ssh roots. So, go forth, and remote mount, using the simpler, more secure, and easier to use SSHFS.


1. If using individual ssh key files for different remote hosts, create a .ssh_config file with an entry(s) similar to the following:

host example_host
   Hostname example.com
   IdentityFile ~/.ssh/privatekeyfile
   IdentitiesOnly yes
   User example_user
   Port 22


10 January 2021
Updated 29 Jan 2021