# autossh



## chatwizrd (Jul 19, 2012)

I am attempting to setup a reverse ssh connection to a server behind a firewall to a public server.

Does anyone know if security/autossh is broken? When I get a disconnect it never attempts to reconnect. If I send the ssh command a -HUP it will reconnect immediately. This problem is not happening on my Debian box. I can't figure out any reason why it wouldn't be working as I am using the same exact script on my Debian server and it reconnects seconds after being disconnected.

I can watch the logs live in screen and it just sits there forever.

The only differences I notice is that my Debian version is running version 1.4b and FreeBSD is running the newest 1.4c.

Here is the script I am using:


```
#!/bin/sh
HOSTNAME=$(hostname)
SSH_OPTIONS="-i /home/nagios/tunnel/$HOSTNAME.key"
# Always assume initial connection will be successful
export AUTOSSH_GATETIME=0
# Disable echo service, relying on SSH exiting itself
export AUTOSSH_PORT=0
# Retry connection time
export AUTOSSH_FIRST_POLL=30
export AUTOSSH_POLL=30
# Log file
export AUTOSSH_LOGFILE=/home/nagios/tunnel/tunnel.log
# Log detail 1-7
#export AUTOSSH_LOGLEVEL=5
# Debug mode
export AUTOSSH_DEBUG=yes

/usr/local/bin/screen /usr/local/bin/autossh -vv -- $SSH_OPTIONS -o 'ControlPath none' -R 1999:localhost:22 nagios@123.456.78.9 -fN
```


----------



## dalecosp (Jul 25, 2012)

I do this via PHP:


```
<?php

$myssh="/usr/bin/ssh me@server";
$mytcping="/usr/local/bin/tcping";
$mysudo="/usr/local/bin/sudo";

$dater=date('r');

system("$myssh $mytcping localhost 2222",$foo);

if ($foo) { // did not return "0", so we must reconnect

system("/usr/bin/ssh -i /home/me/.ssh/identity -fNR 2222:localhost:22 me@server");
system("/bin/echo 'SSH status reset attempted at $dater' >> /tmp/ssh.status");

} else {

   system("/bin/echo 'SSH status OK at $dater' >> /tmp/ssh.status");
}
exit;
?>
```
I imagine a similar strategy could be used in several other languages.


----------

