How to Mount Remote File System over SSH in Linux

Channel: Linux
Abstract: /home/remoteuser on /mntssh type fuse.sshfs (rwLets mount the remote directory. For this example we are mounting /home/remoteuser directory from 192.1

SSHFS is a filesystem based on the SSH File Transfer Protocol (SFTP). On remote side we just need to install SSH server, Since most of SSH servers already support this, there are nothing to do on remote server except installing SSH server. On client side we need to install fuse sshfs packages to mount remote filesystem. Newer version of SSHFS uses FUSE. The FUSE version of SSHFS is rewrite by Miklos Szeredi.

Features of SSHFS:
    • Based on FUSE (Best userspace filesystem framework for linux)
    • Multithreading: more than one request can be on it’s way to the server
    • Allowing large reads (max 64k)
    • Caching directory contents
Step 1 – Install FUSE-SSHFS

For CentOS/RHEL users, Fuse SSHFS is available under epel repository, So make sure you have install epel repository in your system. Now execute following command to install it

On CentOS/RHEL:
# yum install fuse-sshfs
On Ubuntu & Dabian:
$ sudo apt-get update
$ sudo apt-get install sshfs
Step 2 – Mount Remote Directory

Let’s mount the remote server directory using sshfs. Make sure the remote system has a running ssh server with proper ssh connectivity from your system.

First, create a mount point

# mkdir /mntssh

Lets mount the remote directory. For this example we are mounting /home/remoteuser directory from 192.168.1.12 (remote.example.com) system to our local system.

# sshfs [email protected]:/home/remoteuser /opt/mntssh

[Sample output]

The authenticity of host 'remote.example.com (192.168.1.12)' can't be established.
RSA key fingerprint is 77:85:9e:ff:de:2a:ef:49:68:09:9b:dc:f0:f3:09:07.
Are you sure you want to continue connecting (yes/no)? yes
[email protected]'s password:
Step 3 – Verify Mount

After mounting the remote filesystem on the local mount point, verify it by running the mount command.

# mount

/dev/mapper/vg_svr1-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
[email protected]:/home/remoteuser on /mntssh type fuse.sshfs (rw,nosuid,nodev)

Also, navigate to your mount point, you will see files therefrom remote system

# cd /mntssh
# ls
Step 4 – Mount Directory on System Boot

If you want to mount remote filesystem automatically each time when your system reboots, Add following entry to /etc/fstab file. Make sure you have have key based ssh setup between remote and local system.

[email protected]:/home/remoteuser /mntssh fuse.sshfs defaults 0 0
Step 5 – Unmount Directory

If your work is over and you don’t need anymore the mounted directory, Simply unmount it using the following command.

# umount /mntssh

Also remove entry from /etc/fstab file

Ref From: tecadmin

Related articles