The purpose of this project is to facilitate SSHFS mounting at the command-line. In short, this script will read a configuration file to mount remote locations onto the local filesystem using SSHFS. The script supposes that you have ensured that your local account is able to access the remote filesystem using the specified user.
The script is tuned to minimise command-line entry and get you going as quickly as possible, automatically mounting a specific directory, at a specific host onto the local file system at a (configurable) standard location. The format of the configuration file is also tuned to minimise entry.
When run with no mounting specification (see below), the script will attempt to (re)mount all specifications from the configuration files if mounting had been lost. This can be run from a crontab or similar to ensure access to a number of remote locations at all time.
The file should always end with an empty line or a comment. Empty lines are
ignored, comments are lines starting with the #
(hash) character. Otherwise
lines should contain a number of fields separated by the :
(colon) sign. There
should be at least one field. The fields are understood as follows:
- User and hostname specification, e.g. user@hostname, where the user is
optional (and in which case there should not be an
@
sign). When no user is present, the auto mounter will try looking for one in your private ssh configuration file at~/.ssh/config
. When none is found, the user will finally default to your username. - Directory at remote location to mount locally. When this is empty, the entire home of the remote user will be mounted locally
- Port number at the remote location. When no port is present, the auto mounter
will try looking for one in your private ssh configuration file at
~/.ssh/config
. When none is found, this will finally default to22
. - An alias to address the remote location and be used at the command-line for quicker typing, when empty, this will default to the user and hostname specification.
-c
or--config
: Specifies the location of the configuration file. This defaults toautomount.cfg
inXDG_CONFIG_HOME
, which itself defaults to~/.config
.-o
or--options
: Specifies a list of specific options to give to sshfs when mounting the remote location. This defaults to a number of options meant to keep the connection alive as much as possible and resist network failures or hickups.-f
or--force
: Force remounting of the remote, this will skip netcat accessibility check and might be necessary when tunneling through a bastion host.-r
or--root
: Specifies the root location of where remote locations will be mounted on the local filesystem. This defaults to the~/mnt/
directory. Sub-directories with the user and hostname specification will be automatically created.-u
or--unmount
: Unmount instead of the default, which is mounting the remote location.-n
or--netcat
: Location of netcat binary, which is used to test if the remote is accessible and responding at the specified port.
Apart from the options above, the script will take none or a series of remote
specifications to be mounted or unmounted (depending on the presence of the -u
flag). Specifications are either the entire combination of username and
hostname, or the alias specified in the configuration file. When requested to
mount, only remote locations that are not yet mounted will be attempted to be
mounted (unless the -f
flag is specified). When no specification are given,
the script will attempt to mount (or unmount) all known locations from the
configuration file.
sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,IdentityFile=/home/me/.ssh/id_rsa user@server:/home/user/dir dirshare/ should help keeping the connection