1 min read

SSHFS: A Small Guide for Ubuntu Users

SSHFS: A Small Guide for Ubuntu Users
AI generated image

SSHFS, or Secure Shell Filesystem, is a powerful tool that uses SSH to enable the mounting of a remote filesystem on a local machine. The network becomes transparent, making it an efficient and straightforward method for accessing files and directories on a remote server as part of your local machine.

Installation

SSHFS is available for most Linux distributions, including Ubuntu. To install SSHFS on Ubuntu, you can use the apt package manager:

  1. Refresh your package sources by running the following command in your terminal:
sudo apt update
  1. Next, install  sshfs  with the following command:
sudo apt install sshfs

After the installation, there’s no additional configuration needed. You’re now set to start using SSHFS.

Usage

SSHFS is particularly useful when you read from a large set of files interactively. To use SSHFS, you must have an SSH server running on a remote machine.

Let me provide you with an example of how to use SSHFS to mount a remote directory.

In this example, the remote directory is /projects on a remote host named far. The local mount point is ~/far_projects.

  1. Create a local directory that will serve as the mount point:
mkdir ~/remoteserver
  1. Run the SSHFS command to mount the remote directory:
sudo sshfs -o allow_other,default_permissions jondoe@your_other_server:~/ ~/remoteserver

In the command above, -o idmap=user ensures that files owned by the remote user are owned by the local user.

To unmount the filesystem, use the following command:

fusermount -u ~/remoteserver
or
sudo umount ~/remoteserver

You can also add the mount to your /etc/fstab file for persistence across reboots.

johndoe@your_other_server:~/ ~/remoteserver fuse.sshfs noauto,x-systemd.automount,_netdev,reconnect,identityfile=/home/johndoe/.ssh/id_rsa,allow_other,default_permissions 0 0

Conclusion

SSHFS is a secure and efficient tool for mounting remote filesystems on your local machine. It uses SSH, which means it inherits permissions from the SSH user on the remote system. This makes SSHFS an excellent choice for those who need to work with files on a remote server as if they were local.

Happy mounting!