SSH Local Forwarding

Feb 23, 2018
  • Host1 is your localhost
  • Host2 is the server we want to ssh into it
  • Host3 is the server which both connect to Host1 and Host2, It’s our ssh proxy.
# Loal ssh tunnel as sock5
# On Host1
$ ssh  -N -D 127.0.0.1:9090 -p <Host3 Port>  <Host3 User>@<Host3 IP>

# Then you could use 127.0.0.1:9090 as your sock5 proxy
# Locl port forwarding, ssh into Host2 from Host1
# On Host1
$ ssh -NT -L 9090:<Host2> -p <Host3 Port> <Host3 User>@<Host3 IP>

# -N means only to connect host but not use shell
# -T means no TTY
$ ssh -p 9090 <Host2 User>@localhost
# Clear the ssh config for localhost:9090
$ ssh-keygen -R [localhost]:9090