SSHFS (Secure Shell FileSystem), is a tool that allows users to securely access remote filesystems over the SSH protocol. SSHFS can eliminate the need to use FTP/SFTP to transfer files to and from a remote server. For this guide you will need the SSH daemon running on your server. If you do not have the SSH daemon first install before returning to this guide. For this guide we used two Ubuntu 16.10 systems, but sshfs can be installed on any one server.
In this article I will show how to install SSHFS and mount the filesystems over SSH on Ubuntu.
- 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
Follow the below steps to install the SSHFS.
1. First of all install sshfs package using below command.
$ sudo apt-get update $ sudo apt-get install sshfs
2. Lets mount remote server directory using sshfs, make sure remote system has running ssh server with proper ssh connectivity from your system.
First of all create mount point.
$ sudo mkdir /ssh
Now mount the remote directory. For example I am going to mount /home/user directory from 192.168.1.5 (remoteserver.example.com) system to our local system.
$ sudo sshfs [email protected]:/home/user /opt/ssh
You will get some output like below:
The authenticity of host 'remoteserver.example.com (192.168.1.5)' 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:
3. Now verify the mounted directory. After mounting remote filesystem on local mount point, verify it by running 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/user on /opt/ssh type fuse.sshfs (rw,nosuid,nodev)
Also naviate to your mount point, you will see files there from remote system
$ cd /ssh $ ls
4. 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/user /opt/ssh/ fuse.sshfs defaults 0 0
5. f your work is over and you don’t need anymore the mounted directory, Simply unmount is using following command.
$ umount /opt/ssh
Also remove entry from /etc/fstab file.