Sometime we need to copy files and directories from different Linux machines, Most of time Linux admin used scp command to copy files directories. On backend SSH protocol is running to complete this task. But if we need to do so frequently, we have SSHfs which can mount remote file-system through SSH protocol. Below mentioned steps contains how we can install and configure this.

Installation of SSHFS

For Linux, you can use yum to install sshfs packages.

#yum install sshfs -y In my case, this installed three packages, output from /var/log/yum.log

Jul 18 11:16:01 Installed: fuse-2.8.3-4.el6.x86_64

Jul 18 11:16:01 Installed: fuse-libs-2.8.3-4.el6.x86_64

Jul 18 11:16:01 Installed: fuse-sshfs-2.4-1.el6.x86_64

For Ubuntu, you can use apt-get utility.

#apt-get install sshfs



After installation required packages, we can use them and mount remote file-system through SSH.

[root@local-srv11 ~]# mkdir /srv12-home

[root@local-srv11 ~]# sshfs 192.168.1.12:/home /srv12-home

root@192.168.1.12’s password:

[root@local-srv11 ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

/dev/mapper/vg_localsrv11-lv_root ext4 18G 7.4G 9.1G 45% /

tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm

/dev/sda1 ext4 485M 39M 421M 9% /boot

/dev/sdb1 ext2 9.9G 23M 9.4G 1% /vm_images

192.168.1.12:/home fuse.sshfs 37G 9.2G 26G 27% /srv12-home



In this we have provide password for user which have access for this directory that you are trying to mount. So from the server side from where we need to mount, we only need SSH connection and credentials for accessible user.

But this is also possible that we need not to provide password every time, for this we have to save provide SSH keys which will automatic login without credentials.

For this we have create SSH keys, below method used to create SSH keys and mount through keys.

[root@local-srv11 ~]# ssh-keygen -t rsa -b 4096

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

58:9d:61:e5:9a:94:72:c5:6f:6c:9d:a6:1a:13:50:39 root@local-srv11

The key’s randomart image is: <<<<truncate output>>>> [root@local-srv11 ~]# scp .ssh/id_rsa.pub 192.168.1.12:/root/.ssh/authorized_keys

root@192.168.1.12’s password:

id_rsa.pub 100% 738 0.7KB/s 00:00

We can use these SSH key and mount remote SSH directory. Below mentioned output show, how to do this…