SSHFS (Secure SHell FileSystem) enables you to access and interact with a remote filesystem as if it were a local one. This is achieved by mounting the remote filesystem over a secure SSH connection. This method is an alternative to other remote filesystem protocols, such as SAMBA/CIFS or NFS.

SSHFS operates on the SFTP protocol and necessitates SSH access to the remote server. Additionally, the SSH user on the remote server must have the appropriate permissions for the directory you wish to mount.

To mount the remote filesystem of an SSH-enabled host as a local one, you'll need to install and configure SSHFS via the command line. For simple file transfers or copying without mounting the remote filesystem, consider using scp or sftp instead.

Steps to mount remote filesystem with SSHFS:

  1. Open the terminal.
  2. Install SSHFS on your local host.
    localuser@localhost:~$ sudo apt update && sudo apt install --assume-yes sshfs # Ubuntu and Debian variance
    localuser@localhost:~$ sudo dnf --enablerepo=PowerTools --assumeyes install fuse-sshfs # CentOS and Red Hat variance
  3. Verify that you have SSH access to the remote host.
    localuser@localhost:~$ ssh remote-user@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.
    remote-user@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@remotehost:~$ exit
    logout
    Connection to 192.168.111.20 closed.

    Make sure the user that you're connecting to have full access to the directory that you want to mount.

  4. Create a new local directory for the remote filesystem mount point if one doesn't already exist.
    localuser@localhost:~$ mkdir -p /home/localuser/remote
  5. Manually mount the remote filesystem using SSHFS.
    localuser@localhost:~$ sshfs remoteuser@192.168.111.20:/home/remoteuser/shared /home/localuser/remote
    remoteuser@192.168.111.20's password: 
  6. Verify that the mount was successful.
    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. Access the mount point to test its functionality.
    localuser@localhost:~$ touch /home/localuser/remote/file.txt
  8. Unmount the remote SSHFS filesystem.
    localuser@localhost:~$ umount /home/localuser/remote
  9. Confirm that the unmount was successful.
    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 your preferred text editor to configure automatic mounting using SSHFS during system startup.
    localuser@localhost:~$ sudo vi /etc/fstab

    This method require passwordless SSH configured for the user.

  11. Add an SSHFS entry to /etc/fstab.
    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 id command to get the uid and gid of the user.

    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. Mount the remote filesystem via /etc/fstab.
    localuser@localhost:~$ mount /home/localuser/remote
  13. Verify that the mount was successful.
    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.