How To Use SSHFS to Mount Remote File Systems Over SSH

SSHFS (Secure SHell File System) use to mount the remote file system and interact with remote directories and files on a local machine using secure file transfer protocol (SFTP).

In many cases, we fall in difficulties to transfer files to and from a remote system. Especially a development usage scenario where you are coding apps remotely and find yourself uploading a script repeatedly to your server to test. This can become quite a hassle in a very short period of time. In most of the cases, we are using FTP or SFTP for that, but there is a way called SSHFS for System Administrator, Web Developer and those users who want to mount remote file system for development purpose and regular use over and over. Without login each time to remote server. This article may helpful for them.

Step 1: Install SSHFS Client

On Ubuntu/Debian

SSHFS is a Linux-based software you have to install it first. For Ubuntu and Debian apt-get

technhit@ubuntu$ sudo apt-get update
technhit@ubuntu$ sudo apt-get install sshfs

On Redhat

For RHEL use yum installer to instal sshfs.

 technhit@rhel$ yum install sshfs

 On Windows

To install SSHFS in Windows you will need to grab the latest win-sshfs package from the google code repository. A direct download link can be found below. After you have downloaded the package, double-click to launch the installer. You may be prompted to download additional files if so the installer will download the dot NET Framework 4.0 and install it for you.

https://github.com/Foreveryone-cz/win-sshfs/releases/download/1.6.1/WinSSHFS-1.6.1.13-devel.msi

Step 2: Creating SSHFS Mount Directory

After installing SSHFS package you need to create mount directory where the file system to be mounted. In order to do that we create a mount point on /mnt/remote in our local system.

 $ sudo mkdir /mnt/remote                        [for RHEL remove sudo]

 Step 3: Mounting Remote Filesystem with SSHFS

 After creating you mount point directory run the following command to mount your remote directory. In my case I have /home/technhit on Ip 192.168.152.55 (Replace with your remote IP) at my remote system which will be mounted on /mnt/remote in my local system.

# sshfs [email protected]:/home/technhit/ /mnt/remote
$ sudo sshfs -o allow_other [email protected]:/home/technhit/ /mnt/remote [for Ubuntu]

sshfs

mounted fs

If your remote server configured with ssh key authentication. You need to specify the path of your ssh key file to sshfs .

# sshfs -o IdentityFile=~/.ssh/id_rsa [email protected]:/home/technhit/ /mnt/remote    [For RHEL]
$ sudo sshfs -o allow_other,IdentityFile=~/.ssh/id_rsa [email protected]:/home/technhit/ /mnt/remote  [For Ubuntu]

Now you can work with files on your remote server as if it were a physical device attached to your local machine. For instance, if you move to the /mnt/remote directory on your local machine you can create a file locally and the file will appear on your remote server. Similarly, you can copy files into the /mnt/remote folder and this will be uploaded to your remote server in the background.

Step 4: Checking Mount Point with df -hT Command

 $ df-hT

df -hT

Step 5: Permanently Mounting the Remote File System

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 droplets. 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 
$ sudo nano /etc/fstab                        [For Ubuntu]

Put the following line at the end of fstab file.

 sshfs#[email protected]:/home/technhit/ /mnt/remote

fstab

 

The following two tabs change content below.

Subroto Mondal

Chief Coordinator HR&CR
I like Programming and New Technologies. And work with Linux.

One Comment

  • Ok, so I have successfully installed sshfs and have connection to remote repository at ip ending 85 (linux). I have a linux web server on ip ending in 203.
    what is the hyperlink syntax I use on the page on 203 that will use the sshfs link to a linux share on 85.
    eg

    thanking you in advance

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.