FreeBSD-11.1p10 and autossh
Dave Cottlehuber
dch at skunkwerks.at
Thu Jun 14 18:08:14 UTC 2018
On Thu, 14 Jun 2018, at 17:27, James B. Byrne via freebsd-questions wrote:> I cannot seem to configure autossh to work from anything other than
> the command line, which defeats the purpose. I would like it to
> automatically start when the system boots but I have been unsuccessful> in all my attempts to date. I have tried adding this in rc.conf:
>
> autossh -M0 -f -i /root/.ssh/id_ed25519 -L 143:localhost:143
> root at 192.168.216.17
>
> But there is no evidence that this even gets executed. In any case it> is not running after a restart and no error messages are logged.
>
> I created a primitive rd.d script which runs but which does not
> establish a link between the systems. ps reports that autossh is
> running and that it is the parent of a process pid. But that pid does> not exist and there is nothing logged anywhere that I can find to show> that it ever did.
>
> The options that I pass from rc.conf to the rc.d/autossh script are:
>
> autossh_enable="YES" # enable autossh
> autossh_flags='-M0 -f \
> -i "/root/.ssh/id_rsa" \
> -o "ServerAliveInterval 30" \
> -o "ServerAliveCountMax 3" \
> -L "143:localhost:143" \
> -N \
> "root at 192.168.216.17"'
>
> This starts autossh as shown below:
>
> ps -auxw | grep ssh
> root 2971 0.0 0.0 8332 1640 - SsJ 10:52 0:00.00
> autossh: parent of 33977 (8) (autossh)
> root 13736 0.0 0.1 57812 4856 - SsJ 10:52 0:00.00
> /usr/sbin/sshd
> root 32028 0.0 0.1 85228 5620 - SsJ 10:52 0:00.02 sshd:> root at pts/1 (sshd)
> root 34983 0.0 0.0 14828 1804 1 S+J 10:52 0:00.00 grep
> --color ssh
>
>
> But there is no connection to the remote host. If I run autossh from> the command line with the same options then I see this:
>
> autossh -M0 -f -i "/root/.ssh/id_rsa" -o "ServerAliveInterval 30"> -o "ServerAliveCountMax 3" -L "143:localhost:143" -N
> "root at 216.185.71.17"&
>
>
> ps -auxw | grep ssh
> . . .
> root 53110 0.0 0.0 8332 1700 - IsJ 10:56 0:00.00
> autossh: parent of 53777 (1) (autossh)
> root 53777 0.0 0.1 24580 4380 - SJ 10:56 0:00.03
> /usr/bin/ssh -i /root/.ssh/id_rsa -o ServerAliveInterval 30 -o Serv
> . . .
>
>
> The rc.d script is very basic and contains this:
>
>
> source /etc/rc.subr
>
> name="autossh"
> rcvar=autossh_enable
>
> load_rc_config $name
>
> : ${autossh_enable:="NO"}
> : ${autossh_pidfile:="/var/run/autossh.pid"}
> : ${autossh_procname:="/usr/local/bin/autossh"}
>
> start_cmd=${name}_start
> stop_cmd=${name}_stop
>
> pidfile=${autossh_pidfile}
> procname=${autossh_procname}
>
> autossh_start() {
> AUTOSSH_PIDFILE=${autossh_pidfile} ${autossh_procname}
> ${autossh_flags}> AUTOSSH_DEBUG=7
> AUTOSSH_LOGLEVEL=7
> AUTOSSH_LOGFILE="/var/log/autossh.log"
> }
> autossh_stop() {
> kill -9 "$(cat ${AUTOSSH_PIDFILE})";
> rm -f "${AUTOSSH_PIDFILE}"
> }
> run_rc_command "$1"
>
> But this does not work as I expect either. fROM THE CLI 'service
> autossh start' runs autossh but autossh does not establish an ssh
> connection to the target. The pid autossh claims to be the parent of
> does not exist when I search for it using ps. Despite the debugging
> and logging settings nothing appears in the autossh logfile. There is> nothing in /var/log/auth.log on the target host to indicate that an
> ssh connection is even attempted.
>
> This is more of an annoyance than anything else but I am mystified
> that something as basic as this just will not run as I expect. Why
> does autossh work as expected when started from the command line but
I highly recommend spiped https://www.freshports.org/sysutils/spiped/
and leave autossh in the dust where it belongs. It has an rc.d script
and is robust against failure.
A+
Dave
More information about the freebsd-questions
mailing list