Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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)

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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