Create an SSH SOCKS proxy server on localhost:8000 that will re-start itself if something breaks the connection temporarily

autossh -f -M 20000 -D 8000 somehost -N
This command will log you into somehost via SSH and then go into the background (-f). From there, you can point e.g. firefox at localhost:8000 as a SOCKS proxy. Autossh will use port 20000 and 20001 to send and receive test data on those ports to ensure the SSH tunnel is still running, and will try to re-start the tunnel if it goes down. Make sure you have ssh-agent running, or passwordless ssh keys distributed between the two hosts.

10
By: sud0er
2009-02-19 20:17:52

1 Alternatives + Submit Alt

What Others Think

this is fantastic and I use it all the time - is autossh a default package on most systems though?
jlin64 · 504 weeks ago
no, autossh is usually an extra install. Very worth it on desktops, IMO.
sud0er · 503 weeks and 6 days ago
hmm I currently use ssh -i /path/to/publickey -ND localhost:8080 user@proxyserver.com -- if im switching to autossh, how do I setup authentication?
fotoflo · 459 weeks and 1 day ago
autossh -f -i /path/to/key -ND local-IP:PORT User@Server
fotoflo · 459 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: