user3675868 user3675868 - 6 months ago 11
Linux Question

Tunnel SSH: access a server blocked by firewall through another server

abcasdnaksjbdkahsbdhabsjdhabsjdhbasjhdbajshdbajshbdjasbh

Answer

If using openssh:

TRIVIAL WAY

PC> ssh server1_user@server1
server1> ssh server2_user@server2

PROXY WAY

Get a netcat on server1, if you can't install one, you can try to statically compile one (check busybox), download one (find server1 and OS version and check it's repos). If you have python/perl, there are "script implementations" of the command.

On your ~/.ssh/config file add:

Host server1
  HostName 10.0.0.146
  User server1_user

Host server2
  ProxyCommand ssh -C -q server1 /<server1_path_to>/nc 192.168.0.3 22 
  User server2_user

ssh server2 will prompt for both passwords, if you're not using key authentication.

Since OpenSSH 5.4 netcat is not required for proxying

Host server2
  ProxyCommand ssh -W %h:%p server1
  User server2_user

TUNNEL WAY

PC TTY1> ssh -L 2222:192.168.0.3:22 server1_user@server1
PC TTY2> ssh server2_user@localhost -p 2222