Mount a Remote Directory with SSHFS – Coolest Linux Trick Ever!

Coolest Linux Trick Ever!

While I hate to get too excited about anything, I have to say that this trick has been really helpful.  Pretty much all of this can be done by using scp, but using SSHFS to remote mount a filesystem over SSH, really makes it simple to modify a remote file, copy, diff, compare, anything you need.  This is a cool trick, the Coolest Linux Trick Ever!

NFS or Samba not Available

When you need to copy, compare, or edit files on a remote machine it can sometimes be easier to mount the remote directories and use and manipulate the files locally than to ssh over to the other machine.  This is when SSHFS becomes very useful.  While NFS and Samba require time and effort to share a directory or filesystem, SSHFS doesn’t require any changes on the hosting machine at all, and the only changes you need to make on the client machine are insignificant and minor.

All of this is easier to see by showing an quick example.  Let’s suppose that in the home directory of a user named  mary on machine2, I have a file named “file1” that I want to use on machine1.  I can quickly mount the remote directory with sshfs and have access to it.

Install Fuse-sshfs Locally (machine1)

The only thing that needs to be installed is fuse-sshfs which is quickly done with yum:

# yum install fuse-sshfs

Create a MountPoint on the Client Machine (machine1)

We need to create a local directory on machine1 that we can use for mounting machine2’s directory:

# mkdir $HOME/machine2

Mount a Remote Directory with SSHFS

Now, we are ready to mount the remote directory

[root@machine1 ~]# sshfs $HOME/othermachine
The authenticity of host ‘ (x.y.q.z)’ can’t be established.
RSA key fingerprint is ac:1b:ba:d5:1b:28:49:56:a0:df:60:bc:e3:ae:06:48.
Are you sure you want to continue connecting (yes/no)? yes’s password: <type mary’s password here>

Verify the SSHFS Mount

A quick “df” will prove if we have successfully mounted the remote filesystem with SSHFS:

[root@machine1 ~]# df -h /root/machine2        158G  2.0G  148G   2% /root/machine2

Yes.  It mounted fine.  Now I can see and use file1 from machine2:

[root@machine1 ~]# ls /root/machine2

Unmount the Remote Filesystem

When you are done with the files on the other machine, unmount the filesystem and remote the mount point:

[root@machine1 /]# umount /root/machine2
[root@machine1 /]# rmdir /root/othermachine

That’s it!  It was very simple to mount a remote directory on my machine so that I could compare, edit, or otherwise files on machine2 on machine1.  It was nearly instant and was much simpler than NFS or Samba.

The following two tabs change content below.
Jeff has 20 years of professional IT experience, having done nearly everything in his roles of IT consultant, Systems Integrator, Systems Engineer, CNOC Engineer, Systems Administrator, Network Systems Administrator, and IT Director. If there is one thing he knows for sure, it is that there is always a simple answer to every IT problem and that downtime begins with complexity. Seasoned IT professional by day, Jeff hopes to help other IT professionals by blogging about his experiences at night on his blog: You can find Jeff on or LinkedIn at: LinkedIn or Twitter at: Twitter

Latest posts by Jeff Staten (see all)

1 comment for “Mount a Remote Directory with SSHFS – Coolest Linux Trick Ever!

  1. Beau
    October 14, 2013 at 5:24 pm

    I wasnt able to donwload the sshfs package until i updated my repository with RHEL EPEL repo:

    sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

    after that, everything worked great! excellent tutorial!

Leave a Reply

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