SSHFS (Secure SHell FileSystem) which enables to access or mount remote filesystem or directory over SSH File Transfer protocol (SFTP) subsystem of SSH on a local system. Install ‘fuse-sshfs’ packages to mount filesystem or directory on a client system. You need to provide SSH access to the remote system to use SSHFS.
. CentOS Linux 8 Installation with Screenshots
Prerequisites:
. Running Instance, in remote server SSH daemon should be running.
. Password-less SSH from client to remote system in case of persistent mount is required.
Following are the IPs of servers for demo:
Server – 192.168.56.124
Client – 192.168.56.114
Step 1: Passwordless SSH in Linux
Login with user ‘root’ and generate ‘public’ and ‘private’ keys for Password-less SSH (Click on picture below to enlarge it).
$ ssh-keygen
Copy public key on the server (Click on picture below to enlarge it).
$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.56.124
. Click here to know the steps to create password-less SSH in Linux
Step 2: Now, create a directory ‘/sshfsmountpoint‘ in the server (192.168.56.124).
# mkdir /sshfsmountpoint
Step 3: Install fuse-sshfs in the client system.
For CentOS and RHEL 8/7, ‘fuse-sshfs’ package is available under EPEL repository, so install EPEL repository and execute the following command.
Note: root or sudo privileges user access is required to install the packages.
. Install EPEL (Extra Packages Enterprise Linux) repository.
Install EPEL(Click on picture below to enlarge it).
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Once EPEL is installed, run following command to install ‘fuse-sshfs‘ (Click on picture below to enlarge it).
# yum install fuse-sshfs
Step 4: Create a mountpoint as a ‘/mntpoint‘ at a client system (192.168.56.114) and mount remote server directory ‘/sshfsmountpoint‘ with below command (Click on picture below to enlarge it).
$ mkdir /mntpoint
$ sshfs root@192.168.56.124:/sshfsmountpoint/ /mntpoint
As we can see above screenshot, we have manually mounted remote directory ‘/sshfsmountpoint’ on mount point ‘/mntpoint’.
Step 5: Verify mounted directory, and also touched a file ‘client.txt‘ (Click on picture below to enlarge it).
# cd /mntpoint
$ cat > client.txt
After inserting some text, press ‘Ctrl+D’ to exit from console.
Step 5: Persistent Mounting
Create persistent mount to keep your system directory mounted each time the system is rebooted. SSHFS allows permanent mount points to remote directory. In order to do persistent mount, edit ‘/etc/fstab’ file on the client system and add entry as ‘root@192.168.56.124:/sshfsmountpoint/ /mntpoint fuse.sshfs defaults 0 0′ (Click on picture below to enlarge it).
# vi /etc/fstab
(Save and exit from file with ‘:wq!’)
Update ‘fstab’ file to reflect the changes
# mount -a
Now, below screenshot to confirm that remote directory ‘/sshfsmountpoint’ is mounted on ‘/mntpoint’ client system (Click on picture below to enlarge it).