SSH is a highly versatile and secure protocol, allowing remote shell access (through the ssh command) and secure file transfer (through the scp command). SSHFS extends the file transfer concept to provide a filesystem client via FUSE (Filesystem in USErspace).
Assuming you already have shell access to a remote machine, it is trivial to mount a remote part of the filesystem locally and access it over the network as if it were a local filesystem, with the added security of the SSH conduit.
aptitude install sshfs Mounting a Remote Directory
To mount a remote
mkdir <localdir> sshfs <user>@<host>:<dir> <localdir>
Unmounting an SSHFS mount
fusermount -u <localdir>
Combining AutoFS with SSHFS gives a powerful system allowing remote filesystems to be mounted automatically when required. First install AutoFS if it is not already installed
aptitude install autofs
To allow automount to mount the filesystem in the background, you must have SSH public/private key authentication set up with the remote server. Details of this procedure are widely available.
Next create a configuration file for SSHFS filesystems
In this file create an entry for each SSHFS filesystem you wish to automount. These lines take the form of
<mount> -fstype=fuse,<options> :sshfs\#<user>@<host>\:<dir>
Note: The # is because FUSE wants a parameter of the form sshfs#
In /etc/auto.master add the new configuration file
/var/autofs/sshfs /etc/auto.sshfs uid=<uid>,gid=<gid>,--timeout=30,--ghost
Some of the options here are:
– set your user ID for the mount (from /etc/passwd).
– set your group ID for the mount (from /etc/group).
- --timeout=30 – sets the timeout. If the filesystem is not accessed within this time autofs will unmount it.
Create a symlink to the various SSHFS mount points in /etc/auto.sshfs
ln -s /var/autofs/sshfs/<mount> /mnt/<mount-name>