I was having some issues starting up autossh to multiple destinations using
a rc.d script. The following configuration works connecting an OpenBSD
machine to two remote endpoints for remote forwarding back to sshd on the
local machine.
There's likely a better way to do this, but this has been tested to work
with both `rcctl start' and `rcctl stop' commands. Don't forget to enable
the daemon with `rcctl enable autossh'.
Hope it helps.
### ~autossh-user/.ssh/config
Host REMOTE_GW_1
HostName remote-gw-1.example.org
IdentityFile /home/autossh-user/.ssh/id_rsa
RemoteForward 2222 localhost:22
ServerAliveInterval 15
ServerAliveCountMax 3
ExitOnForwardFailure yes
Host REMOTE_GW_2
HostName remote-gw-2.example.org
IdentityFile /home/autossh-user/.ssh/id_rsa
RemoteForward 2222 localhost:22
ServerAliveInterval 15
ServerAliveCountMax 3
ExitOnForwardFailure yes
### /etc/rc.d/autossh
#!/bin/sh
# start autossh tunnel
# requires $daemon_user with $HOME/.ssh/config and keys
daemon="/usr/local/bin/autossh"
daemon_flags_1="-M 0 -f -N REMOTE_GW_1"
daemon_flags_2="-M 0 -f -N REMOTE_GW_2"
daemon_user="autossh-user"
. /etc/rc.d/rc.subr
rc_reload=NO
pexp="autossh:.*"
rc_start() {
${rcexec} "${daemon} ${daemon_flags_1}" && \
${rcexec} "${daemon} ${daemon_flags_2}"
}
rc_cmd $1