Mounting a remote directory over SSH integrates remote storage into the local filesystem, enabling file operations with standard tools while traffic remains encrypted. Using SSHFS, remote paths appear as part of the local directory tree, which simplifies editing, synchronisation, and backups across different systems.

The SSHFS client is a FUSE-based filesystem that talks to the remote host using the SFTP subsystem of OpenSSH. After authentication, file operations such as open, read, and write on the mount point are translated into SFTP requests on the selected remote directory, subject to the permissions of the remote user account.

Stable operation depends on working SSH connectivity, correct ownership and permissions on the remote directory, and appropriate authentication method. For automatic mounting at boot using /etc/fstab, passwordless authentication and network availability are essential; incorrect entries or unreachable hosts can delay startup or block mounting until the issues are resolved.

Steps to mount remote filesystem with SSHFS:

  1. Open a terminal on the local Linux system.
  2. Install SSHFS on the local Ubuntu or Debian system.
    localuser@localhost:~$ sudo apt update && sudo apt install --assume-yes sshfs

    On CentOS or Red Hat, install the fuse-sshfs package instead.

    localuser@localhost:~$ sudo dnf --enablerepo=PowerTools --assumeyes install fuse-sshfs
  3. Verify that password-based SSH access to the remote host functions correctly.
    localuser@localhost:~$ ssh remoteuser@192.168.111.20
    The authenticity of host '192.168.111.20 (192.168.111.20)' can't be established.
    ECDSA key fingerprint is SHA256:w3b7BfZzQrrY75Fx1XYH0t2RVkiXb7r6+gcC5umTR7o.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added '192.168.111.20' (ECDSA) to the list of known hosts.
    remoteuser@192.168.111.20's password: 
    Welcome to Ubuntu 20.10 (GNU/Linux 5.8.0-25-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    
    0 updates can be installed immediately.
    0 of these updates are security updates.
    
    
    The programs included with the Ubuntu system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.
    
    Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
    applicable law.
    
    remoteuser@192.168.111.20:~$ exit
    logout
    Connection to 192.168.111.20 closed.

    Ensure the remote account used for SSHFS has full read or write access to the directory selected for mounting.

  4. Create a local directory to serve as the mount point for the remote filesystem.
    localuser@localhost:~$ mkdir -p /home/localuser/remote
  5. Mount the remote directory manually using SSHFS.
    localuser@localhost:~$ sshfs remoteuser@192.168.111.20:/home/remoteuser/shared /home/localuser/remote
    remoteuser@192.168.111.20's password: 
  6. Confirm that the mount is present in the filesystem table output.
    localuser@localhost:~$ df -h
    Filesystem                                          Size  Used Avail Use% Mounted on
    tmpfs                                               391M  1.8M  389M   1% /run
    /dev/sda3                                            20G  6.4G   12G  35% /
    tmpfs                                               2.0G     0  2.0G   0% /dev/shm
    tmpfs                                               5.0M  4.0K  5.0M   1% /run/lock
    tmpfs                                               4.0M     0  4.0M   0% /sys/fs/cgroup
    /dev/sda2                                           512M  7.8M  505M   2% /boot/efi
    tmpfs                                               391M  104K  391M   1% /run/user/1000
    remoteuser@192.168.111.20:/home/remoteuser/shared   20G  6.4G   12G  35% /home/localuser/remote
  7. Create a test file inside the mount point to validate read and write access.
    localuser@localhost:~$ touch /home/localuser/remote/file.txt
  8. Unmount the SSHFS filesystem when access is no longer required.
    localuser@localhost:~$ fusermount -u /home/localuser/remote

    The fusermount command unmounts FUSE filesystems owned by the current user without requiring elevated privileges.

  9. Confirm that the unmount removed the remote entry from the filesystem table.
    localuser@localhost:~$ df -h
    Filesystem                             Size  Used Avail Use% Mounted on
    tmpfs                                  391M  1.8M  389M   1% /run
    /dev/sda3                               20G  6.4G   12G  35% /
    tmpfs                                  2.0G     0  2.0G   0% /dev/shm
    tmpfs                                  5.0M  4.0K  5.0M   1% /run/lock
    tmpfs                                  4.0M     0  4.0M   0% /sys/fs/cgroup
    /dev/sda2                              512M  7.8M  505M   2% /boot/efi
    tmpfs                                  391M  104K  391M   1% /run/user/1000
  10. Open /etc/fstab with a preferred text editor to prepare automatic mounting at system startup.
    localuser@localhost:~$ sudo vi /etc/fstab

    Automatic SSHFS mounting requires passwordless SSH for the specified user, and incorrect entries in /etc/fstab can cause boot delays or prevent mounting until corrected.

  11. Add an SSHFS entry to /etc/fstab pointing to the remote directory and local mount point.
    sshfs#remoteuser@192.168.111.20:/home/remoteuser/shared  /home/localuser/remote fuse user,_netdev,reconnect,uid=1000,gid=1000,idmap=user  0   0

    Use the id command to obtain the appropriate uid and gid values.

    localuser@localhost:~$ id
    uid=1000(user) gid=1000(user) groups=1000(user),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),121(lpadmin),132(lxd),133(sambashare)
  12. Trigger mounting via /etc/fstab to ensure the configuration is valid.
    localuser@localhost:~$ sudo mount /home/localuser/remote
  13. Verify that the remote filesystem appears again in the mounted filesystems list.
    localuser@localhost:~$ df -h
    Filesystem                                          Size  Used Avail Use% Mounted on
    tmpfs                                               391M  1.9M  389M   1% /run
    /dev/sda3                                            20G  6.4G   12G  35% /
    tmpfs                                               2.0G     0  2.0G   0% /dev/shm
    tmpfs                                               5.0M  4.0K  5.0M   1% /run/lock
    tmpfs                                               4.0M     0  4.0M   0% /sys/fs/cgroup
    /dev/sda2                                           512M  7.8M  505M   2% /boot/efi
    tmpfs                                               391M  108K  391M   1% /run/user/1000
    remoteuser@192.168.111.20:/home/remoteuser/shared   20G  6.4G   12G  35% /home/localuser/remote
Discuss the article:

Comment anonymously. Login not required.