0
0

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/config を使わずに複数の踏み台を経由して SSH 接続する

Posted at

1. 概要

踏み台経由で SSH 接続する必要がある場合、~/.ssh/config に ProxyCommand を書くことがあると思います。
事情があって ~/.ssh/config を編集出来ない場合に ~/.ssh/config を使わずに ssh コマンドのオプションで直接 ProxyCommand を指定する方法を記載します。

2. 踏み台が1台のパターン

ホスト 秘密鍵 ユーザー hostname or ip
踏み台 ~/.ssh/humidai.key humidai_user humidai.xxxxx.jp
SSH接続したいサーバー ~/.ssh/dest.key dest_user 192.168.0.1
$ ssh -o ProxyCommand="ssh -i ~/.ssh/humidai.key -W %h:%p humidai_user@humidai.xxxxx.jp" -i ~/.ssh/dest.key dest_user@192.168.0.1

3. 踏み台が2台のパターン

ホスト 秘密鍵 ユーザー hostname or ip
踏み台の踏み台 ~/.ssh/humidai_2.key humidai_2_user humidai_2.xxxxx.jp
踏み台 ~/.ssh/humidai.key humidai_user humidai.xxxxx.jp
SSH接続したいサーバー ~/.ssh/dest.key dest_user 192.168.0.1
$ ssh -o ProxyCommand='ssh -o ProxyCommand="ssh -i ~/.ssh/humidai_2.key -W humidai.xxxxx.jp:22 humidai_2.xxxxx.jp" -i ~/.ssh/humidai.key -W %h:%p humidai.xxxxx.jp' -i ~/.ssh/dest.key dest_user@192.168.0.1
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?