How to Use SSHFS on Linux?

SSHFS (SSH File System) allows you to mount a remote file system over a secure SSH connection. This enables you to access and manipulate files on a remote server as if they were stored locally on your Linux machine. SSHFS combines the security of SSH with the convenience of a file system interface.

Installing SSHFS

First, install SSHFS on your Linux system using the package manager. For Ubuntu/Debian systems

sudo apt-get install sshfs

For RHEL/CentOS/Fedora systems

sudo yum install sshfs
# or for newer versions
sudo dnf install sshfs

The installation includes all necessary dependencies. Ensure you have SSH access to the remote server before proceeding.

Basic SSHFS Mounting

To mount a remote file system, you need the remote server's IP address or hostname, your username, and the directory path you want to access.

Create a Local Mount Point

First, create a directory where the remote file system will be mounted

mkdir ~/remote-files

Mount the Remote File System

Use the following command to mount the remote directory

sshfs username@remote_server:/path/to/remote_directory ~/remote-files

Replace username with your remote username, remote_server with the server's IP or hostname, and /path/to/remote_directory with the actual path.

You'll be prompted for the remote server password. After successful authentication, verify the mount

df -h ~/remote-files

Working with Remote Files

Once mounted, you can work with remote files using standard Linux commands

List Remote Files

ls -la ~/remote-files

Copy Files to Remote System

cp local_file.txt ~/remote-files/

Edit Remote Files

nano ~/remote-files/config.txt

Advanced Usage

Unmounting

To safely unmount the remote file system

fusermount -u ~/remote-files

Mounting with Options

You can specify additional options for better performance and security

sshfs username@remote_server:/path/to/directory ~/remote-files \
  -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3

Automatic Mounting with fstab

For permanent mounting, add an entry to /etc/fstab

sudo nano /etc/fstab

Add this line

username@remote_server:/path/to/directory /home/user/remote-files fuse.sshfs defaults,_netdev,user 0 0

Key Options and Features

Option Purpose
-o reconnect Automatically reconnect if connection drops
-o allow_other Allow other users to access the mount
-o compression=yes Enable SSH compression for better performance
-o cache=yes Enable local caching

Common Use Cases

  • Remote Development Edit files on remote servers using local editors

  • File Synchronization Access remote files without copying them locally

  • System Administration Manage configuration files on multiple servers

  • Backup Operations Access remote backup directories seamlessly

Conclusion

SSHFS provides a secure and convenient way to access remote files over SSH connections. It eliminates the need for FTP or other file transfer protocols while maintaining the security of SSH. With proper configuration, SSHFS can significantly streamline remote file management tasks on Linux systems.

Updated on: 2026-03-17T09:01:39+05:30

435 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements