Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was looking for a method to connect to arbitrary SSH servers through a known SSH proxy, without having to hardcode those target servers.

For example, let's say that I cannot access from my current location, because port 22 is firewalled, but I can connect to my SSH server at home because it goes through a non-firewalled port. What is the most practical way to configure SSH so that when I explicitly want to connect through my proxy, it does so?

I wanted an easy solution; one that would be as simple as typing:

$ ssh user@server-i-want-to-connect-to.proxy

An example would be "ssh".

share|improve this question
when you say proxy, do you mean an HTTP proxy? If so, check out corkscrew – jackweirdy Sep 13 '12 at 22:33
No, by proxy I mean an SSH server to which you can connect to (a machine you own). I found out a way to do it, but I must wait for 8 hours before I can answer my own question... – sleblanc Sep 13 '12 at 23:10
up vote 2 down vote accepted

Add something like this to your .ssh/config

Host *%myproxy
    ProxyCommand ssh /bin/netcat -w 1 $(echo %h | cut -d%% -f1) 22

Then you can simply run a command like ssh user@server-i-want-to-connect-to%myproxy. You do need to have netcat installed on your server acting as a proxy.

share|improve this answer
This is almost exactly the answer I was going to post (could not because I need more rep to post an answer before 8 hours has passed) however I would add the "%p" percent_replace instead of the hardcoded port 22 to the netcat command. This allows one to specify an arbitrary port number to connect to. Oh and I used sed instead of cut. – sleblanc Sep 14 '12 at 2:07

Your Answer


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.