SSH File System (SSHFS): Mount Remote File Systems on Linux & Windows Print

  • SSHFS installation, SSHFS, Windows, Linux, SSHFS examples, remote file systems, mount remote file system
  • 232

Introduction

SSHFS (SSH File System) allows you to mount remote directories over SSH, enabling seamless access to files on remote servers as if they were on your local machine. It’s especially useful for managing remote resources securely without the need for FTP or other file transfer protocols.

Benefits of SSHFS

  • Secure file access using SSH encryption.
  • Cross-platform compatibility (Linux, Windows, macOS).
  • Ease of use with minimal setup.
  • No need for additional server-side software; uses existing SSH infrastructure.

Prerequisites

  • Access to a remote server with SSH enabled.
  • SSH credentials (username and password or private key).
  • SSHFS package installed on your Linux or Windows system.

Installing SSHFS on Linux

Install SSHFS using your distribution’s package manager:

# For Ubuntu/Debian
sudo apt update && sudo apt install sshfs -y

# For CentOS/RHEL
sudo yum install epel-release -y
sudo yum install sshfs -y

# For Fedora
sudo dnf install sshfs -y

# For Arch Linux
sudo pacman -S sshfs

Installing SSHFS on Windows

On Windows, use WinFsp and SSHFS-Win:

  1. Download and install WinFsp from its official website.
  2. Download SSHFS-Win from its GitHub page and install it.
  3. Once installed, use the File Explorer or Command Prompt to mount remote directories.

Basic Usage of SSHFS on Linux

1. Mount a Remote Directory

mkdir ~/remote_dir
sshfs username@remote-server:/path/to/remote/dir ~/remote_dir

Replace username, remote-server, and /path/to/remote/dir with the appropriate values.

2. Unmount the Remote Directory

fusermount -u ~/remote_dir

Basic Usage of SSHFS on Windows

1. Mount a Remote Directory

Open Command Prompt and run:

sshfs.exe username@remote-server:/path/to/remote/dir X:

Replace X: with the desired drive letter.

2. Unmount the Remote Directory

To unmount, run:

net use X: /delete

Advanced Usage

1. Mount with Key-Based Authentication

sshfs -o IdentityFile=~/.ssh/id_rsa username@remote-server:/remote/dir ~/local_mount

2. Configure Persistent Mounts

Add the following line to /etc/fstab:

sshfs#username@remote-server:/remote/dir /mnt/remote_dir fuse _netdev,user,idmap=user,IdentityFile=/path/to/private_key 0 0

3. Performance Optimization

    • Use the reconnect option for automatic reconnections:
sshfs -o reconnect username@remote-server:/remote/dir ~/local_mount
    • Use caching options (cache=yes) for better performance:
sshfs -o cache=yes username@remote-server:/remote/dir ~/local_mount

Troubleshooting Tips

  • Permission Denied: Check SSH permissions and ensure the remote path is accessible.
  • Connection Timeout: Verify network connectivity and SSH server status.
  • Mount Fails: Ensure SSHFS is installed correctly and the mount point exists.

Conclusion

SSHFS is a powerful tool for securely accessing and managing remote files over SSH. By following this guide, you can easily mount and work with remote directories on both Linux and Windows systems.


Was this answer helpful?

« Back