SSHFS (SSH Filesystem) is an open-source file system that is based on FUSE for accessing remote directories over an SSH connection. Basically, the drive can be mounted on any operating system if it uses FUSE. It uses the SFTP protocol, which is enabled on most SSH servers.
It has several advantages over something like Samba or NFS, that it does not require you to do additional configuration on the server side, you only need the OpenSSH CLI tool running on it. Although it does utilize more resources on both the Client and host side as all the data transferred is encrypted and decrypted in the process.
In this tutorial, we will learn how can you install and use SSHFS to mount a remote filesystem client on all the major Linux distributions and also learn how can you set up the client so that it gets automatically mounted on every startup.
Also read: Bottles – Easily install Windows apps on Linux
Installing SSHFS on Linux
Depending upon your Linux distribution, you can install the following package on your client:
# On Debian and Ubuntu based distributions:
sudo apt update && sudo apt install sshfs
# On RHEL/CentOS
suodo yum install sshfs
And needless to say, you will have to install the OpenSSH package on your server, but it is mostly installed on all the servers. Still, you can check by typing:
openssh --version
If it is not installed, then you can install it by using the default package manager on your system:
# On Debian and Ubuntu based distribution:
sudo apt install openssh
# On RHEL or CenOS:
sudo yum install openssh
Also read: How To Change SSH Port in Linux and Ubuntu
Mounting a remote FileSystem
You can type the following commands to mount remote storage on your PC:
sshfs [user@]host:[remote_directory] mountpoint [options]
Where the user and host need to be your user on the host server and IP address of the server. If you have a config file, then this command will read it and use the host settings. If you do not specify the remote directory, then the home directory itself gets mounted.
Also, make sure you create a directory where your storage will be mounted. For example:
sshfs aadesh@192.168.1.50: new
In the above example, I have not specified the remote directory, so the entire Home directory gets mounted in the ‘new’ folder. You can also set up passwordless SSH login so that you do not have to type the username and password every time you try to access your remote machine.
Mounting the folder at boot
To avoid typing out the commands every time you log in, you can just let the FSTAB file do the work for you. Just open your /etc/fstab file in a text editor like this:
# To open the fstab file, type:
sudo vim /etc/fstab
# For nano users:
sudo nano /etc/fstab
And add the following lines:
user@host:/remote/dir /local/mountpoint fuse.sshfs defaults 0 0
Note that you will have to change everything in the above line from user to host addresses and the mount point as well. It should look something like this:
While adding a permanent mount, make sure that you have set up SSH login with a key-based authentication.
Unmounting a file system
If, for some reason, you want to unmount the SSHFS Network Storage from your PC, you can type the following command:
umount /local/mountpoint
# For example, I can type:
umount /home/aadesh/new
Summary
SSHFS is a great tool for anyone looking for encrypted network-attached storage, as it provides a secure way to store and access files across multiple devices. It is especially useful for those who need to securely access files on remote servers, as it is encrypted and thus secure against snooping. However, SSHFS is a bit more resource-hungry than other alternatives, and if you don’t need encryption, you may want to consider other options.
One of those alternatives is Samba Share, a network-attached storage solution that runs unencrypted on a local server instead of a remote system. Samba Share is a great choice for those who want to store and access files without the overhead of encryption, and it can be set up to run on any Windows, Linux or Mac server. It is also very popular, as it is compatible with most operating systems, and it can be used to share files between different clients and servers.
Samba Share also offers a wide range of features, such as the ability to set up specific access rights and permissions, share printers and scanners, and even restrict access to particular computers. It also supports file locking, so multiple people can access the same files without overwriting each other’s work.
We hope you learned how to install and use sshfs using this tutorial. Let us know if you need any help!