How to Mount a Remote Directory on Your Local PC with sshfs
1. Install sshfs
on Your Local PC
- On a Linux machine (e.g., Ubuntu/Debian), install the
sshfs
package:sudo apt update sudo apt install sshfs
- For macOS, install
sshfs
via Homebrew:brew install macfuse brew install sshfs
- For Windows, use WinFsp and SSHFS-Win.
2. Create a Local Mount Point
Create a local directory where the remote filesystem will be mounted, for example:
mkdir ~/remote_home
3. Mount the Remote Directory with sshfs
Use the following command to mount the remote directory:
sshfs username@remote_host:/path/to/remote/home ~/remote_home
- Replace
username
with your username on the remote server. - Replace
remote_host
with the address of your remote server (e.g.,192.168.1.100
orexample.com
). - Replace
/path/to/remote/home
with the path of the directory you want to mount (e.g.,/home/user
).
4. Useful Options
Here are some useful options to customize the mount:
- Verbose mode (for debugging): Add
-o debug
. - Compression: Add
-o compression=yes
to compress transferred data. - Read-only mode: Add
-o ro
to mount in read-only mode. - Custom SSH port: If the server uses a non-standard SSH port (e.g., 1234):
sshfs username@remote_host:/path/to/remote/home ~/remote_home -p 1234
- Preserve local permissions:
sshfs username@remote_host:/path/to/remote/home ~/remote_home -o uid=$(id -u),gid=$(id -g)
5. Unmount the Directory
To unmount the directory when you are done, use:
fusermount -u ~/remote_home
6. Automate with /etc/fstab
(Optional)
If you want to mount the directory automatically at startup:
- Add a line to the
/etc/fstab
file:sshfs#username@remote_host:/path/to/remote/home ~/remote_home fuse.sshfs defaults,_netdev 0 0
- Set up your SSH key to avoid entering the password every time.
7. Use an SSH Configuration File (Optional)
If you have specific SSH options (such as ProxyCommand
or a custom port), configure them in ~/.ssh/config
. Example:
Host remote_server
HostName example.com
User username
Port 1234
ProxyCommand ssh -W %h:%p jump_host
Then, simply use:
sshfs remote_server:/path/to/remote/home ~/remote_home
If you encounter any issues or need additional help, feel free to ask!