Mount remote directory with sshfs

In computing, 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. Using SSHFS, a remote file system may be treated in the same way as other volumes (such as CDs, DVDs, USB flash drives and shared disks).

Installing SSHFS on a Ubuntu / Debian

# apt-get install sshfs

Installing SSHFS on a RHEL / CentOS

# yum install fuse-sshfs

How TO mount remote filesystem?

The syntax is following:

# sshfs user@server1 /path/to/mount_point
# sshfs user@server1 /path/to/mount_point options

In the first place, we need to create a directory where sshfs filesystem will be mounted.

# mkdir /mnt/server1

I’m going to mount the filesystem using root user:

# sshfs [email protected]:/ /mnt/server1/
 
##  For connections that uses ssh keys ##
# sshfs -o IdentityFile=~/.ssh/keyfile /mnt/server1/

Check if filesystem is mounted successfully with df command:

# df -f
Filesystem              Size  Used Avail Use% Mounted on
/dev/mapper/wks05-root  487G  114G  350G  25% /
[email protected]:/     20G   12G  6.8G  64% /mnt/server1

To unmount

umount /mnt/server1