Overview
sshfs mounts the file system of a remote server onto a local directory via an SSH connection, allowing you to access and manage remote files as if they were local. This is particularly useful for frequently editing remote files or handling large amounts of data.
Key Features
- Based on FUSE (Filesystem in Userspace)
- Data transfer over secure SSH connection
- Direct access and editing of remote files as if local
- Provides various mount options (permissions, caching, compression, etc.)
Installation
sshfs is not included by default in most Linux distributions, so you need to install it using your package manager.
Debian/Ubuntu
sudo apt update && sudo apt install sshfs
Install using the apt package manager.
Fedora/CentOS/RHEL
sudo dnf install sshfs
Install using the dnf (or yum) package manager.
Key Options
sshfs offers various options to finely control the mount behavior. Most options are used after the `-o` flag, separated by commas.
Connection and Permissions
Performance and Behavior
Generated command:
Try combining the commands.
Description:
`sshfs` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Various ways to mount and use remote directories locally with sshfs.
Basic Mount
mkdir -p /local/mount/point
sshfs user@remote_host:/remote/path /local/mount/point
Mounts `/remote/path` on the remote server to `/local/mount/point` locally. The mount point must be created beforehand.
Using a Specific SSH Port
sshfs -o port=2222 user@remote_host:/remote/path /local/mount/point
Attempts to connect via SSH using a port other than the default port 22 (e.g., 2222).
Allowing Access for Other Users
sshfs -o allow_other user@remote_host:/remote/path /local/mount/point
Allows users other than the one who mounted the filesystem to access it.
Using an SSH Key File
sshfs -o IdentityFile=~/.ssh/id_rsa user@remote_host:/remote/path /local/mount/point
Authenticates using an SSH key file instead of a password.
Unmounting
fusermount -u /local/mount/point
Unmounts the mounted file system. `fusermount` is used to safely unmount FUSE file systems.
Tips & Precautions
Useful tips and points to be aware of when using sshfs.
Importance of Unmounting
After completing your work, always unmount the filesystem using the command `fusermount -u
Performance Optimization
In environments with high network latency, you can improve performance by using the `cache=yes` option. Conversely, `compression=yes` can increase CPU usage, so consider the balance between network bandwidth and CPU resources when using it.
Permission Issues
The `allow_other` option permits other users to access the mounted file system. Use it with caution regarding security. If necessary, you can use the `uid` and `gid` options to mount with the permissions of a specific user/group.
Automatic Mounting (fstab)
To automatically mount sshfs at system boot, you can edit the `/etc/fstab` file. However, this method requires additional configuration such as SSH key authentication and may cause issues depending on network connectivity, so it should be configured with care.