1

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 github.com 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 [email protected]

An example would be "ssh [email protected]".

2
  • 1
    when you say proxy, do you mean an HTTP proxy? If so, check out corkscrew agroman.net/corkscrew
    – jackweirdy
    Sep 13, 2012 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, 2012 at 23:10

1 Answer 1

2

Add something like this to your .ssh/config

Host *%myproxy
    ProxyCommand ssh [email protected] /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.

1
  • 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, 2012 at 2:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .