Direct multi-hop ssh connection

Posted on In QA

How to use multi-hop ssh connection without needs to ssh multiple times?

As a example, you are connecting to server.example.com through proxy.example.com from laptop.example.com as follows:

laptop ----> proxy ----> server

2 possible methods:

Method 1: Use the similar method as in Directly SSH to hosts using internal IPs through the gateway. Add this to your ~/.ssh/config on laptop:

Host server.example.com
  ProxyCommand ssh -q proxy.example.org nc %h %p

Method 2:

Run

ssh proxy.example.com ssh server.example.com

That is, you first log on proxy.example.com and then ssh from there to server.example.com.

For both methods, Automatic Password-less SSH Login is your good friend.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *