1. Home
  2. How to use SSHFS to mount Re-mote File Systems over SSH

How to use SSHFS to mount Re-mote File Systems over SSH

How to use SSHFS to mount Re-mote File Systems over SSH
How to use SSHFS to mount Re-mote File Systems over SSH


It can become cumbersome to transfer files to and from a VPS. For example: a development usage scenario in which you are coding apps remotely and find yourself uploading a script repeatedly for your virtual server to test which can quickly turn into quite the hassle. There is a way to mount your VPS File system onto your local computer so that you can make changes as you go and treat your VPS as local storage.
In this tutorial, we will teach you this process.

Installing SSHFS

On Ubuntu/Debian

SSHFS is a Linux based software which has to be installed on your local computer. On Ubuntu and Debian based systems the easiest option to do that is to use apt-get.

sudo apt-get install sshfs

For Mac OSX

You may install SSHFS on Mac OSX but first you must download FUSE and SSHFS from the osxfuse site

On Windows

In order to install SSHFS on Windows, you will have to get the latest ‘win-sshfs’ package from the google code repository; for this, you may use the direct download link below. Once you have downloaded the package, double click to launch the installer. You might be asked to download extra files, one of them should be the ‘.NET Framework 4.0’, it will install it for you.

Mounting the Remote File System

The instructions below could work for both Ubuntu/Debian and OSX.  If you are interested in instructions for Windows, you may find it at the bottom of this tutorial.
Before we begin, you will have to create a local directory, so you can mount the VPS’s file system.

sudo mkdir /mnt/VPS <--replace "VPS" to what you would like.

You can now use ‘sshfs’ to mount the file system locally along with the following command. In case the VPS was made with a password login, the command below should do the trick. You will be prompted for your virtual server’s root password while following this step.

sudo sshfs -o allow_other,defer_permissions
root@xxx.xxx.xxx.xxx:/ /mnt/VPS

If your VPS is currently configured for login with ssh key authorization, you will have to tell ‘sshfs’ to use your public keys using the command below. You will be prompted to enter the passphrase you were using while creating your keys with ‘ssh-keygen’.

sudo sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/id_rsa
root@xxx.xxx.xxx.xxx:/ /mnt/VPS

You may now work with files on your VPS as if it was a physical device connected to your local machine.
For example, if you were to move to the ‘/mnt/VPS’ directory on your local machine, you could create a file locally and that file would show up on your virtual server.
In the same way as copying the files into the ‘/mnt/VPS’ folder, they are going to be uploaded to your VPS in the background.
It is wise to remember that this procedure just grants a temporary mount point to your VPS. If the virtual server or local machine is powered off or restarted, you will have to go through the same procedure in order to mount it once more.

Unmounting the Remote File System

When you no longer require the mount point, you may simply unmount it using the following command.

sudo umount /mnt/VPS

Permanently Mounting the Remote File System

SSHFS also grants an option to allow a setup of permanent mount points to the remote file systems. This will set a mount point which will persist through restarts of both your local machine and VPSs. To set up a permanent mount point, you will have to edit the ‘/etc/fstab’ file located on the local machine to automatically mount the file system every time the system has booted.
To begin, open the ‘/etc/fstab’ file using a text editor and modify it with the following command below.

sudo nano /etc/fstab

Go to the bottom of the file and add the following entry.

sshfs#root@xxx.xxx.xxx.xxx:/ /mnt/VPS

Now save the changes to ‘/etc/fstab’ and reboot if needed. It is important to know that, once you permanently mount your VPS file system locally, it is a potential security risk. If your local machine is compromised, it allows a direct route to your VPS. It is not suggested to setup permanent mounts on production servers.

Using Win-SSHFS to Mount Remote File Systems on Windows

Once you have launched the ‘win-sshfs’ program, you are going to be presented with a graphical interface to cause the procedure of mounting a remote file share easy.
Step 1: Click the ‘Add’ button in the lower left corner of the window.

Step 2: Type a name for the file share in the ‘Drive Name’ field.

Step 3: Type the IP of your VPS in the Host field.

Step 4: Type in your SSH port. (Keep it as port 22 unless you have changed it manually)

Step 5: Type your username in the ‘Username’ field. (Depending on if you have set up user accounts manually, you have to enter root in this field).

Step 6: Type your SSH password in the ‘password’ field. (Note that, on Windows, you are going to be required to have your VPS configured for password logins other than ‘ssh-key-authentication’).

Step 7: Type your desired mount point in the ‘Directory’ field. (Enter ‘/‘ to mount the file system from root. Likewise you can enter ‘/var/www’ or ‘~/  for your home directory).

Step 8: Choose the drive letter you would like Windows to use for your VPSs file system.

Step 9: Press the ‘Mount’ button to connect to the VPS and mount the file system.

Your virtual server’s file system is now going to be available from ‘My Computer’ as the drive letter you chose in step 8.

Updated on November 28, 2017

Was this article helpful?

Leave a Comment

[apsl-login-lite login_text='Please login with a social account']