SSHFS: Installation and Mounting

SSHFS (SSH Filesystem) is a filesystem client to mount and interact with directories and files located on a remote server or workstation over a normal ssh connection. The client interacts with the remote file system via the SSH File Transfer Protocol (SFTP), a network protocol providing file access, file transfer, and file management functionality over any reliable data stream that was designed as an extension of the Secure Shell protocol (SSH) version 2.0. The current implementation of SSHFS using FUSE is a rewrite of an earlier version.

FUSE (Filesystem in Userspace) is an interface for userspace programs to export a filesystem to the Linux kernel. The FUSE project consists of two components: the fuse kernel module (maintained in the regular kernel repositories) and the libfuse userspace library (maintained in this repository). libfuse provides the reference implementation for communicating with the FUSE kernel module.

A FUSE file system is typically implemented as a standalone application that links with libfuse. libfuse provides functions to mount the file system, unmount it, read requests from the kernel, and send responses back.

Installation

SSHFS is Linux based software that needs to be installed on your server. On Ubuntu and Debian based systems it can be installed through apt-get.

apt-get install sshfs

Mounting

To start we will need to create a local directory in which to mount the verser's file system.

mkdir /mnt/name_of_directory

Now we can use sshfs to mount the file system locally with the following command:

Now you can work with files on your remote server (or like in this tutorial's example on local folder) as if it were a physical device attached to your local machine. For instance, if you move to the /mnt/name_of_directory directory on your local machine you can create a file locally and the file will appear on your virtual server. Likewise you can copy files into the /mnt/name_of_directory folder and they will be uploaded to your remote server in the background.

To see all mounted devices you can use command:

df -hT

Note: This process provides only a temporary mount. If the VPS is restarted, you will need to use the same process to mount it again.

Unmounting

When you no longer need the mount point you can simply unmount it with the command:

umount /mnt/name_of_directory

Permanent Mounting

SSHFS also allows for setting up permanent mount points to remote file systems. This would set a mount point that would persist through restarts of both your local machine and servers. In order to set up a permanent mount point, we will need to edit the /etc/fstab file on the local machine to automatically mount the file system each time the system is booted.

First we need to edit the /etc/fstab file with a text editor.

nano /etc/fstab

Note: If nano is not installed on your server you can do it with command:

Note: Permanently mounting your VPS file system locally is a potential security risk. If your local machine is compromised it allows for a direct route to your server. Therefore it is not recommended to setup permanent mounts on production servers.