193
202

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

多段 SSH で秘密鍵を「ローカルに持つ」パターンと「踏み台に持つ」パターン

Last updated at Posted at 2020-09-15

はじめに

多段 SSH の設定方法はググればたくさんでてきますが,「踏み台に秘密鍵を持つ」パターンの情報が少なくて躓いたので,今後のためにメモしておきます。

Special Thanks: @chitoku

ローカルに持つ場合

通常はこちらの方法が望ましいです。

[A] ----> [B] ----> [C]
 |
 "~/.ssh/id_rsa_for_B"
 "~/.ssh/id_rsa_for_C"
Host B
  Hostname B.example.com
  User user_b
  IdentityFile ~/.ssh/id_rsa_for_B

Host C
  Hostname C.example.com
  User user_c
  IdentityFile ~/.ssh/id_rsa_for_C
  ProxyJump B

参考: linux - SSH from A through B to C, using private key on A - Server Fault

踏み台に持つ場合

秘密鍵の漏洩リスクがあるためあまり推奨されませんが,踏み台の秘密鍵を全ユーザで共有している場合などには有効です。

[A] ----> [B] ----> [C]
 |         |
 |         "~/.ssh/id_rsa_for_C"
 |
 "~/.ssh/id_rsa_for_B"
Host B
  Hostname B.example.com
  User user_b
  IdentityFile ~/.ssh/id_rsa_for_B

Host C
  Hostname C.example.com
  User user_c
  ProxyCommand ssh -o 'ForwardAgent yes' B 'ssh-add ~/.ssh/id_rsa_for_C && nc %h %p'

参考: linux - SSH from A through B to C, using private key on B - Server Fault

193
202
4

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
193
202

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?