How to Mount Remote Directories over SSH via SSHFS on Ubuntu Linux

When it comes to accessing remote directories on Linux systems, including Ubuntu, you have many different methods available. If you want to make folders accessible to remote users and do it securely, you can use sFTP.

For Linux clients, SSHFS (SSH Filesystem) is another great tool. It is a sub-system that comes with an SSH server and is enabled by default, based on FUSE for mounting remote directories over an SSH connection.

Instead of setting up an entirely new server or process for making remote directories and folders available to users, you can use your existing SSH server to do that. No need for additional configurations or FTP servers.

This brief tutorial shows students and new users how to install and configure SSHFS on Ubuntu 18.04 | 16.04 LTS servers.

When you’re ready, follow the steps below:

Installing SSHFS on Ubuntu

SSHFS packages are available in Ubuntu’s default software repositories. So all you need to do to install it is to run the commands below:

sudo apt update
sudo apt install sshfs

After installing it, continue below to learn how to mount directories.

Mounting SSHFS Directories

Now that SSHFS is installed, you can use the mount command to access remote directories over SSH via SSHFS.

The SSHFS mount command format is shown below:

sshfs [user@]host:[remote_directory] mountpoint [options]

To mount a remote directory locally on your Ubuntu machine, you first create a location or mount point that will be synced with the remote side.

Run the commands below to create a folder called sshfs in your home folder. This is where the remote folder will be mounted and accessed locally.

mkdir $HOME/sshfs

You can then use the count commands to mount the remote directory locally through SSHFS.

sshfs richard@192.168.10.2:/RemoteSSHFS $HOME/sshfs

Replace “richard” with the username created on your server and “192.168.10.2” with the actual IP address of your remote instance.

To unmount the directory above, you run the commands below:

cd && fusermount -u $HOME/sshfs

To avoid typing the password each time you mount the remote directory, you can read this post to learn how to configure SSH key authentication. With it, you won’t have to time your password every time you want to mount the remote directory.

Permanently Mount Remote Folder on Local Machine

If you want to permanently mount the remote directory you need to edit the local machine’s/etc/fstab file and add a new entry. Doing this will always keep the mount point available even if you reboot your machine.

This way when your system boots up it will automatically mount the remote directory.

To mount a remote directory over SSHFS from /etc/fstab, use fuse.sshfs as the filesystem type.

Run the commands below to open the /etc/fstab file.

sudo nano /etc/fstab

Then add the line below into the file and save.

sshfs richard@192.168.10.2:/RemoteSSHFS $HOME/sshfs fuse.sshfs  defaults  0  0

You should make sure that password-less SSH authentication is enabled on the SSH server you’re connecting to so you don’t always have to enter a password.

Windows users can mount the remote location using the commands below using programs like SSHFS-Win and WinFsp

\\sshfs\user@host[\PATH]

That should be it!

Congratulations! You have successfully installed and enabled SSHFS and mount remote directories.

You may also like the post below: