When it comes to accessing remote directories on Linux systems, including Ubuntu, there are many different methods available to you. 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 too to use. It is a sub-system that comes with SSH server and 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:
Step 1: Installing SSHFS on Ubuntu
SSHFS packages are available in Ubuntu 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.
Step 2: 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.
You can then use the count commands to mount the remote directory locally through SSHFS.
sshfs email@example.com:/RemoteSSHFS $HOME/sshfs
Replace “richard” with the actual 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 everytime 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 firstname.lastname@example.org:/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.
That should it!
Congratulations! You have learned how to install and enable SSHFS and mount remote directories successfully.
You may also like the post below: