Run command on init and restart on errors

2

I have internet access on my PC through proxy through SSH, so every time I need to execute ssh -L PORT:SERVER:PORT LOGIN@SERVER and then type a password. After each network failure or reconnect this command has to be executed again. I've got bored of it and look for a way to do this automatically: first run this after boot (it doesn't seem to be a problem - put this command in some init file and that's all) and then rerun it (if possible, then type password) on each network failure. Is it possible, and how?

OS Linux (Debian)

aplavin

Posted 2012-10-04T18:49:10.480

Reputation: 173

Answers

1

You can use autossh, use the autossh command to monitor the connection and reconnect when needed. (make sure you replace the ssh with autossh)

autossh -L PORT:SERVER:PORT LOGIN@SERVER

Here is the Linux Man page: http://linux.die.net/man/1/autossh

david.tanner

Posted 2012-10-04T18:49:10.480

Reputation: 151

0

Of course if you use SSH I strongly suggest you to use public key authentication in order not to have to insert the password every time.

You could use a passwordless key, which would be quite secure as long as you limit this key at the remote server (by means of the $HOME/.ssh/authorized_keys), so that the theft of your computer will not allow anyone to get full access to your proxy server.

You can launch this autossh from /etc/network/if-up.d/ and kill it from /etc/network/if-down.d/. If you launch it always, regardless of the connection status, you would need to export AUTOSSH_GATETIME=0, so that the first fail would not prevent autossh to keep trying.

I wonder why such a usual setup is not available in NetworkManager.

Raúl Salinas-Monteagudo

Posted 2012-10-04T18:49:10.480

Reputation: 1 058