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
To mount a remote <dir> at the local mount point <localdir>:
mkdir <localdir>
sshfs <user>@<host>:<dir> <localdir>
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
touch /etc/auto.sshfs
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>
and <options> is typically rw,nodev,nonempty,allow_other,max_read=65536.
Note: The # is because FUSE wants a parameter of the form sshfs#<user>@<host>\:<dir> and the \ is to escape the # since autofs will see it as the start of a comment. The spacing and position of the first colon is also important.
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:
- uid=<uid> - set your user ID for the mount (from /etc/passwd.
- gid=<gid> - 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>
