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
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
For RHEL use yum installer to instal sshfs.
technhit@rhel$ yum install sshfs
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.
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 firstname.lastname@example.org:/home/technhit/ /mnt/remote $ sudo sshfs -o allow_other email@example.com:/home/technhit/ /mnt/remote [for Ubuntu]
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 firstname.lastname@example.org:/home/technhit/ /mnt/remote [For RHEL] $ sudo sshfs -o allow_other,IdentityFile=~/.ssh/id_rsa email@example.com:/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
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.