Skip to content

SSHFS: Mounting a Remote File System over SSH

Advertisement

When using Linux, it’s common to work with servers that are not nearby. To handle files and folders on these distant servers, you need a way to reach their files securely. One good way to do this is by connecting to the remote file system over SSH (Secure Shell). SSHFS is a tool that lets you connect to folders on a remote server through SSH, right from your own computer. To get SSHFS, you simply install it using the package manager specific to your Linux distribution. Once installed, SSHFS allows you to access and manage remote directories as if they were local, providing a secure and straightforward way to work with files on remote servers. This secure method uses SSH, a trusted protocol, to ensure that your data remains safe while you handle remote files.

This article will show you how to set up your Linux system so you can use and change files on a remote server just like they were on your own computer.

Prerequisites

Before we begin, you will need the following:

  • A Linux-based operating system installed on your local machine.
  • A remote server running Linux with SSH access.
  • SSH keys or a password for authentication.
  • SSHFS (SSH File System) package installed on your local machine.

Step 1: Installing SSHFS

SSHFS is a tool that lets you connect to folders on a remote server through SSH, right from your own computer. To get SSHFS, you simply install it using the package manager specific to your Linux distribution.

  • For Debian-based distributions (e.g., Ubuntu), use the following command:
    sudo apt install sshfs 
    
  • For RHEL-based distributions (e.g., CentOS), use the following command:
    sudo yum install sshfs 
    
  • For Arch-based distributions, use the following command:
    sudo pacman -S sshfs 
    

Step 2: Creating a Mount Point

Before mounting the remote file system, you need to create a mount point on your local machine. This is the directory where the remote file system will be mounted. To create a mount point, use the “mkdir” command:

mkdir ~/remote-files 

Step 3: Mounting the Remote File System

To mount the remote file system, use the “sshfs” command, followed by the remote user, the remote server’s IP address or hostname, the remote directory, and the local mount point:


sshfs [user]@[remote-server]:[remote-directory] [local-mount-point]

For example:

sshfs john@192.168.1.100:/home/john/files ~/remote-files 

If you are prompted for a password, enter the remote user’s password. If you have set up SSH keys for authentication, the process will use them automatically.

Step 4: Navigating the Mounted File System

Once the remote file system is mounted, you can access it like any other directory on your local machine. To navigate the remote file system, use standard Linux commands such as “cd”, “ls”, “cp”, “mv”, and “rm”.

For example:

cd ~/remote-files 
ls -l 

Step 5: Unmounting the Remote File System

To unmount the remote file system, use the “fusermount” command with the “-u” option, followed by the local mount point:


fusermount -u [local-mount-point]

For example:

fusermount -u ~/remote-files 

Conclusion

By connecting to a remote file system over SSH in Linux, you can easily access and handle files on remote servers just like they’re on your own computer. This safe and efficient way makes managing remote files simpler and improves your work process. With the steps in this guide, you can now easily set up your system to access remote file systems, making the most of what Linux has to offer.

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

4 Comments

  1. This did not work on RHEL 8.
    sudo yum install fuse-sshfs
    Updating Subscription Management repositories.
    Unable to read consumer identity

    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

    Red Hat Enterprise Linux 8 for x86_64 – AppStre 41 MB/s | 26 MB 00:00
    Red Hat Enterprise Linux 8 for x86_64 – BaseOS 44 MB/s | 28 MB 00:00
    No match for argument: fuse-sshfs
    Error: Unable to find a match: fuse-sshfs

  2. We want to monitor SSHFS mount point with SNMP in Ubuntu but it doesn’t show any SSHFS mount point. Maybe because it is encrypted. How we can solve this?

    Note: we don’t have problem with NFS.

    snmpwalk -v 2c -c public localhost UCD-SNMP-MIB::dskTable
    or

    snmpwalk -v 2c -c public localhost HOST-RESOURCES-MIB::hrFSRemoteMountPoint
    When we request with above commands there is no mountpoint in result but we have MountPoint when we do df.

    df

  3. HI i did all of the things and it has an error ” connection peer rest”
    what should I do ?

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top