単純にsshをカスケードした場合の図:

 % ssh gateway ssh target command args

 [localhost]             [gateway]                       [target]

                                                         command args
                         _________________________________|______

                         ssh target                      sshd
                         ________________________________________
                          |
 stdin/out               stdin/out
 _|_______________________|_____________

 ssh gateway             sshd
 _______________________________________

gatewayからtargetにログインするのに、targetにprivate keyを置くかAgentForwardingをつかってlocalhostの鍵でtargetの認証を行うか二通りある。

ncでトンネルをつくって接続した場合の図:

 % ssh -o 'ProxyCommand ssh gateway nc %h %p' target command args

 [localhost]             [gateway]                       [target]

                                                         command args
 stdin/out                                                |
 _|______________        _________________________________|______
                                   . . . . . . . . . . .
 ssh target              nc %h %p  : . . . . . . . . . . sshd
                                   : :
 ____________: :_        __________: :___________________________
  |          : :          |        : :
 stdin/out   : :         stdin/out : :
 _|__________: :__________|________: :___
             : : . . . . . . . . . : :
             : . . . . . . . . . . . :
 ssh gateway             sshd
 ________________________________________

localhostの鍵でgatewayとtargetの両方にログインする。