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)


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


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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.