- Posted on
- • Filesystem
Mounting Remote Filesystems Over SSH with `sshfs`
- Author
-
-
- User
- Linux Bash
- Posts by this author
- Posts by this author
-
A Handy Guide to Mounting Remote Filesystems Over SSH with sshfs
For Linux users, accessing files across different systems is a common requirement, especially for those who manage servers or use multiple machines connected over a network. While there are various methods to access or transfer files between machines, mounting a remote filesystem over SSH using sshfs
offers a flexible, secure and simple way to work with remote files as if they were local. In this guide, we'll delve into how to utilize sshfs
to mount remote filesystems over SSH, making your workflow more integrated and efficient.
What is sshfs
?
SSH Filesystem (sshfs
) is a user-space file system client that allows you to mount a remote filesystem using Secure Shell (SSH). It leverages the SFTP (SSH File Transfer Protocol) subsystem, which provides a secure connection to manipulate remote files securely over an encrypted connection. The utility of sshfs
lies in its ability to seamlessly integrate remote resources into your local filesystem, enabling standard applications and commands to operate on remote files directly.
Prerequisites
Before we start, ensure you have the following:
1. A local machine running Linux.
2. Access to a remote server where you have SSH access.
3. sshfs
installed on your local machine. If sshfs
isn't installed, you can typically install it from your distribution’s package manager. For example, on Ubuntu-based systems, you can use:
bash
sudo apt-get install sshfs
How to Mount a Remote Filesystem Using sshfs
Creating a Mount Point
First, create a directory on your local system where you will mount the remote filesystem. This could be anywhere you have permission to write, but for the sake of example, let’s create it in your home directory.
mkdir ~/remoteDir
Mounting the Remote Filesystem
With
sshfs
, you can mount the remote directory by running:sshfs [user]@[host]:[remote_directory] [local_mount_point]
For instance, if your username is
alice
, the remote host isexample.com
, and you want to access the remote directory/home/alice/docs
, you would run:sshfs alice@example.com:/home/alice/docs ~/remoteDir
This command mounts the remote directory
/home/alice/docs
to your local directory~/remoteDir
.Accessing and Manipulating Files
Once mounted, you can access and manipulate files in the
~/remoteDir
as if they were on your local machine. Open, edit, save, and manage files using your local tools and editors.Unmounting the Filesystem
When finished, it's important to unmount the remote filesystem properly to ensure all data is correctly syncronized. Use the following command:
fusermount -u ~/remoteDir
Tips and Tricks
Persistent Mounting: If you need the mount to persist across reboots, consider adding an entry in the
/etc/fstab
or using a systemd service for a cleaner setup.SSH Key Authentication: For smoother operations without entering your password every time, set up SSH key authentication for logging into the remote server without manual intervention.
Options and Performance:
sshfs
includes several options that you can use to optimise performance, such as caching methods and specifying bandwidth limits. Checkman sshfs
for detailed usage.
Conclusion
sshfs
offers an incredibly convenient method for accessing remote filesystems directly from your file manager or terminal, fully leveraging the security of SSH without the overhead of more complex network file systems like NFS or SMB. Whether you're handling administrative tasks, accessing documents, or running backup scripts, sshfs
can simplify the way you interact with remote servers. Start incorporating it into your work routine for streamlined, secure file management across your networked machines.