Sshfs
From ArchWiki
Contents |
Introduction
You can use sshfs to mount a remote system - accessible via ssh - to a local folder, so you will be able to do any operation on the mounted files with any tool (copy, rename, edit with vim, etc.). Using sshfs instead of shfs is generally preferred as a new version of shfs hasn't been released since 2004.
Installation
To install the needed packages, do:
# pacman -S sshfs
This should install fuse and sshfs, and maybe other packages.
Usage
First a kernel module should be loaded, so as root, do:
# modprobe fuse
(You can put fuse into the module-list of /etc/rc.conf to auto-load at boot.)
Mounting
You will use the command sshfs. To mount a remote directory:
# sshfs USERNAME@HOSTNAME_OR_IP:/PATH LOCAL_MOUNT_POINT SSH_OPTIONS
For example:
# sshfs sessy@mycomputer:/home/sessy /mnt/sessy -C -p 9876
Where 9876 is the port number.
Also, make certain that before connecting, you set the file permissions for any local client folders you will attempt to mount a remote directory to. I.e., don't have everything owned by root!
SSH will ask for the password, if needed. If you don't want to type in your password 49 times a day, than read this: How to Use RSA Key Authentication with SSH.
Unmounting
To unmount the remote system:
# fusermount -u LOCAL_MOUNT_POINT
Example:
# fusermount -u /mnt/sessy
Tips
To quickly mount a remote dir, do some file-management and unmount it, put this in a script:
sshfs USERNAME@HOSTNAME_OR_IP:/PATH LOCAL_MOUNT_POINT SSH_OPTIONS mc ~ LOCAL_MOUNT_POINT fusermount -u LOCAL_MOUNT_POINT
This will mount the remote directory, launch MC, and unmount it when you exit.
Thunar has issues with FAM and remote file access. If you experience remote folders not displaying, getting kicked back to the home directory, or other remote file access issues through Thunar, replace fam with gamin. Gamin is derived from fam.
pacman -S gamin nano /etc/rc.conf #remove fam in daemons
Troubleshooting
Connection reset by peer
- If you are trying to access the remote system with a hostname, try using its IP address, as it can be a domain name solving issue. Make sure you edit /etc/hosts with the server details.
- Adding the option '
sshfs_debug
' (as in 'sshfs -o sshfs_debug user@server ...
') can help in resolving the issue. - If you're trying to sshfs into a router running DD-WRT or the like, there is a solution here.
- Forum thread: sshfs: Connection reset by peer
fstab
An example on how to use sshfs to mount a remote filesystem through /etc/fstab
sshfs#USERNAME@HOSTNAME_OR_IP:/REMOTE/DIRECTORY /LOCAL/MOUNTPOINT fuse defaults 0 0
Take for example a line from my fstab
sshfs#llib@192.168.1.200:/home/llib/FAH /media/FAH2 fuse defaults 0 0
Although the above will not work automatically unless you are using a ssh key for the user. Using SSH Keys.
If you want to use sshfs with multiple users :
sshfs#user@domain.org:/home/user /media/user fuse defaults,allow_other 0 0
Note: With the above method, umount complains that the filesystem is not in fstab. To get around this, remove the 'sshfs#
' prefix, change the filesystem from 'fuse
' to 'fuse.sshfs
', and create a script '/sbin/mount.fuse.sshfs
':
#!/bin/bash DEVICE="$1" MOUNTPOINT="$2" OPTIONS="$4" OPTIONS="${OPTIONS/,noauto/}" OPTIONS="${OPTIONS/,user/}" # workaround to conflicting 'user' options # in fstab, specify 'login=joe' instead of 'user=joe' OPTIONS="${OPTIONS/,login=/,user=}" exec /usr/bin/sshfs "$DEVICE" "$MOUNTPOINT" -o "$OPTIONS"