The SSH File System, or SSHFS, is a filesystem client that you can mount on your local device to interact with files on the remote device. SSH establishes this connection using the Secure Shell File Transfer Protocol (SFTP).
Moreover, using its cryptographic protocol, SSH ensures data integrity and confidentiality. If your daily tasks include administrating a remote device or server, you are bound to use SSHFS. Hence, you need to learn how to use the SSH File System. So, this short guide will demonstrate how to set up and use SSHFS without much effort.
How to Setup and Use SSHFS
You can install SSHFS on both your local and remote devices. Most Linux distributions, such as Ubuntu, Fedora, RHEL, etc., include SSHFS in their package repositories. Start by updating the package list and upgrading installed packages using the following commands:
Operating System | Command |
Debian/Ubuntu | sudo apt update && sudo apt upgrade |
CentOS/Fedora/RHEL | sudo dnf check-update && sudo dnf update |
Arch Linux | sudo pacman -syu |
openSUSE | sudo zypper update |
Now, execute one of the below commands according to your distributions. Note that RHEL-based systems identify this utility as fuse-sshfs.
Operating System | Command |
Debian/Ubuntu | sudo apt install sshfs |
CentOS/Fedora/RHEL | sudo dnf install fuse-sshfs |
Arch Linux | sudo pacman -S sshfs |
openSUSE | sudo zypper install sshfs |
After installing the utility, proceed to mount the remote directory using the ‘sshfs’ command as follows:
Here, replace user with your username on the remote system, remote_server with the IP address or the hostname of the remote server, /path/to/remote/directory with the directory you intend to mount from the remote server, and /path/to/mount with the location where you want to mount it on the local device. Let’s look at an example:
If you execute the sshfs command for the first time, the system will ask you to enter the password. SSHFS will mount your desired remote directory locally at the specified mount point upon successful authentication. When you are done, you can unmount the remote directory using:
In the above command, /path/to/mount indicates the path you mount the directory in the earlier steps. With the above step, you have successfully set up SSHFS. However, the remote directory will unmount when you shut down your system.
If you want to mount any specific directory automatically with every system boot, add an entry in the /etc/fstab file. However, you would need to have root privileges. For instance, follow the below steps to auto-mount a remote directory using SSHFS. Open the file using a text editor– nano /etc/fstab
Append into it:
Finally, save and exit the editor to save the entry.
Wrapping Up
This is how you can set up and use SSHFS in your Linux system to access the remote server without hassles. SSHFS is nothing but a filesystem client that you can use to mount on your local device and access the remote server. If you are a beginner, we recommend that you use the commands correctly, or else you may face errors while setting up the connection.