Install & Configure SSHFS on CentOS/RHEL/Ubuntu
Q. What is SSHFS ?
-- 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. We Can use it as Alternative of NFS.
Features of SSHFS:
1. Based on FUSE (Best userspace Filesystem Framework for Linux).
2. Multithreading: more than one request can be on it’s way to the server.
3. Allowing large reads (max 64k).
4. Caching Directory Contents.
Scenario :
=======
10.100.97.39 ser3.domain.com (SSHFS Server)
10.100.97.40 ser4.domain.com (SSHFS Client)
Step: 1. Bind Host File (on Both Server) :
# vi /etc/hosts
10.100.97.39 ser3.domain.com ser3
10.100.97.40 ser4.domain.com ser4
-- Save & Quit (:wq)
Step: 2. Stop the IPTables & Disable Selinux (on Both Server) :
# service iptables stop
# chkconfig iptables off
# vi /etc/sysconfig/selinux
SELINUX=disabled
-- Save & Quit (:wq)
Step: 3. Update the Date Time on the Server (on Both Server) :
For CentOS User :
# yum -y install ntp
# service ntpd restart
# ntpdate pool.ntp.org
# chkconfig ntpd on
For Ubuntu User :
# apt-get -y install ntp
# service ntp restart
# ntpdate pool.ntp.org
Step: 4. Reboot the System :
# init 6
Step: 5. Install FUSE-SSHFS (on Both Server) :
Note: For CentOS/RHEL users, Fuse SSHFS is Available under EPEL Repository, So make sure you have Install EPEL Repository in your System.
For CentOS/RHEL User :
# yum -y install epel-release
# yum -y install fuse-sshfs
For Ubuntu & Dabian User :
$ sudo apt-get update
$ sudo apt-get -y install sshfs
Step: 6. Mount Remote Directory (on Client SSHFS Server) :
Note: Lets mount Remote Server Directory using sshfs, make sure remote system has 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 10.100.97.39 (ser3.domain.com) System to our Local System.
# sshfs root@ser3.domain.com:/home/remoteuser /mntssh
[Sample Output]
The authenticity of host 'ser3.domain.com (10.100.97.39)' can't be established.
RSA key fingerprint is 90:41:70:63:04:60:31:84:34:b8:38:21:50:32:86:dd.
Are you sure you want to continue connecting (yes/no)? yes
root@ser3.domain.com's password: Remote Server Root Password Here.
Step: 7. Verify Mount (on Client SSHFS Server) :
After Mounting Remote Filesystem on Local Mount Point (/mntssh), Verify it by Running Mount Command.
# mount
/dev/xvda2 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)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/xen type xenfs (rw)
root@ser3.domain.com:/home/remoteuser on /mntssh type fuse.sshfs (rw,nosuid,nodev)
Also Navigate to your Mount Point, you will see Files there from Remote System.
# cd /mntssh
# ls
Step: 8. Mount Directory on System Boot :
Note: If you want to Mount Remote Filesystem Automatically each time when your System Reboots, Add following Entry :
# vi /etc/fstab
root@ser3.domain.com:/home/remoteuser /mntssh fuse.sshfs defaults 0 0
-- Save & Quit (:wq)
Note: Make sure you have have key based ssh Setup between Remote & Local System. Otherwise Fstab Fail to Mount the Remote Filesystem.
Step: 9. SSH Key Based Authentication Setup (On Both Server) :
On Ser3 (10.100.97.39) :
# ssh-keygen -t rsa
# ssh-keygen -t dsa
# cd /root/.ssh
# cat id_rsa.pub >> authorized_keys
# cat id_dsa.pub >> authorized_keys
# scp authorized_keys root@ser4.domain.com:/root/.ssh/
On Ser4 (10.100.97.40) :
# ssh-keygen -t rsa
# ssh-keygen -t dsa
# cd /root/.ssh
# cat id_rsa.pub >> authorized_keys
# cat id_dsa.pub >> authorized_keys
# scp authorized_keys root@ser3.domain.com:/root/.ssh/
Step: 10. Now lets Test if Both Servers can SSH each other without Password or not :
On Ser3 (10.100.97.39) :
[root@ser3 ~]# ssh ser4
Last login: Wed Aug 10 15:32:06 2016 from 10.100.97.39
[root@ser4 ~]# exit
[root@ser3 ~]# ssh ser4 date
Wed Aug 10 15:32:16 IST 2016
On Ser4 (10.100.97.40) :
[root@ser4 ~]# ssh ser3
Last login: Wed Aug 10 15:32:06 2016 from 10.100.97.40
[root@ser3 ~]# exit
[root@ser4 ~]# ssh ser3 date
Wed Aug 10 15:32:06 2016 IST 2016
Step: 11. Unmount Directory :
If your work is over & you don’t Need anymore the mounted Directory, Simply unmount is using Following command.
# umount /mntssh
Thanks For Visiting on My Blog, For More Tutorials Keep Visiting My Blog