SSHFS – Easily Mount a storage/server over SSH.

Set Up SSHD To Share Files Using Ssh Across Devices

SSHFS (SSH File System) is an open-source filesystem that is based on FUSE for accessing remote directories over an SSH connection. 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 SSHFS 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
Installing SSHFS On Fedora
Installing SSHFS On Fedora

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 typing:

# 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
Mounting A Filesystem Using SSH
Mounting A Filesystem Using SSH

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 command every time you try to access your server.

Mounting 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:

Add The Config To Your FSTAB File
Add The Config To Your FSTAB File

While adding a permanent mount, make sure that you have set up SSH login with a key-based authentication.

Unmounting a drive

If for some reason, you want to detach the Network Storage from your PC, you can type the following command:

umount /local/mountpoint

# For example, I can type:
umount /home/aadesh/new
Unmounting A Network Attached Storage
Unmounting A Network Attached Storage

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. 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!