LoginSignup
14
13

More than 5 years have passed since last update.

サーバーを中継し更に中継する 多段SSH

Posted at

Host fumidai1
  User <1個目の中継サーバーユーザー>
  HostName <1個目の中継サーバー>

#ssh fumidai2と打てばfumidai2まで入れる
Host fumidai2
  User <2個目の中継サーバーユーザー>
  HostName <2個目の中継サーバー>
  IdentityFile <必要であれば>
  ProxyCommand ssh fumidai1 nc %h %p

#ssh Goalと打てばGoalまで入れる
Host Goal
  User <Goalのユーザー名>
  HostName <Goalのサーバー>
  IdentityFile <通る必要のある鍵が必要>
  ProxyCommand ssh fumdai2 nc %h %p

ほんで、トンネルを開けたい場合
(sshするだけでなく、他のアプリなどで該当サーバーに接続したい場合

#サーバーGoalの1個前のサーバーの設定に
Host fumidai2
  User <2個目の中継サーバーユーザー>
  HostName <2個目の中継サーバー>
  IdentityFile <必要であれば>
  ProxyCommand ssh fumidai1 nc %h %p
#以下を追記
  LocalForwad <使いたいLocalPort> <Goalのサーバー>:<Goalのポート>

で ssh -N -f Goalでトンネルが開くので、使いたいLocalPortに向けて接続設定を行えば、
他のアプリなどでも接続出来るようになる。

14
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
13