How to Mount Remote Servers Locally Using Linux sshfs

Managing files on a remote Linux server typically involves using command-line utilities like SCP or rsync. While effective, these tools require you to constantly push and pull files back and forth. If you want to interact with remote files exactly as if they were stored on your own hard drive, the best solution is SSHFS (SSH File System). This powerful utility allows you to securely mount a remote directory to your local Linux machine over an encrypted SSH connection.

Why SSHFS is Better Than Traditional File Transfers

SSHFS creates a seamless bridge between your local computer and a remote server. Once connected, you can open remote text files in your local text editor, drag and drop files using your local file manager, and execute local scripts against remote data. Because it operates entirely over standard SSH, it requires no additional configuration on the remote server—if you can SSH into the machine, you can use SSHFS.

What You Need Before Starting

To follow this guide, you will need a local Linux machine and SSH access to a remote Linux server. You must also have the appropriate permissions on the remote server to access the directory you intend to mount. Ensure you know the IP address or hostname of the remote server and your login credentials.

Installing SSHFS on Your Local Machine

SSHFS is not always installed by default on Linux distributions, but it is readily available in most official repositories. You only need to install it on your local machine; the remote server requires no modifications.

If you are using Ubuntu, Debian, or Linux Mint, open your terminal and run:

sudo apt update && sudo apt install sshfs

If you are using Fedora, Red Hat, or CentOS, use:

sudo dnf install sshfs

For Arch Linux users, the command is:

sudo pacman -S sshfs

Creating a Local Mount Point

Before you can mount the remote directory, you must create a local directory to act as the destination (the mount point). This empty directory will serve as the gateway to your remote files.

To create a new directory named remote_server in your home folder, run:

mkdir ~/remote_server

Mounting the Remote Directory

You are now ready to establish the connection. The syntax for the sshfs command requires your remote username, the server address, the path to the remote directory, and the path to your local mount point.

Use the following command structure, replacing the example details with your own:

sshfs username@server_address:/path/to/remote/directory ~/remote_server

For example, if your username is admin, the server IP is 192.168.1.50, and you want to mount the /var/www/html directory, the command is:

sshfs [email protected]:/var/www/html ~/remote_server

If you have not set up SSH keys, you will be prompted to enter your password. Once authenticated, the command will silently return you to the prompt. If you navigate to ~/remote_server using your file manager or the terminal, you will now see the files from your remote server.

Unmounting the Remote Directory safely

When you have finished working, it is crucial to properly unmount the directory to prevent data corruption or frozen terminal sessions. Never simply delete the local folder.

To safely sever the connection, use the fusermount command:

fusermount -u ~/remote_server

Once the command completes, the remote connection is closed, and your local ~/remote_server directory will be empty again.

Troubleshooting Common SSHFS Errors

If the connection drops unexpectedly, your local mount point may become unresponsive, resulting in a “Transport endpoint is not connected” error. If this occurs, you can force the unmount process using the following command:

sudo umount -l ~/remote_server

After forcing the unmount, you can safely attempt to reconnect using the standard sshfs command.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.