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?

ssh-keyscanをプロキシ環境下で使う

Posted at

背景

ssh-keyscan コマンドは ~/.ssh/config の設定を無視し、直接ターゲットホストへ接続を試みます。また、HTTP/HTTPS プロキシを利用するオプションもありません。そのため、プロキシ環境下で ssh-keyscan を利用するには工夫が必要です。

解決方法

この問題は socat を利用することで解決できます。socat はデータ転送を柔軟に制御できるツールで、今回のようなプロキシ経由の TCP 通信を簡単に実現できます。

ホスト ポート
プロキシサーバー proxy 3128
ターゲット ssh.github.com 443

表のような条件の場合の実行例を次に示します。

1. socat をバックグラウンドで実行する

socat TCP-LISTEN:1234,fork PROXY:proxy:ssh.github.com:443,proxyport=3128 &
  • TCP-LISTEN:1234,fork
    • ローカルのポート 1234 でリッスンし、接続ごとに新しいプロセスを生成(fork)
  • PROXY:proxy:ssh.github.com:443,proxyport=3128
    • proxy:3128 を介して ssh.github.com:443 に接続

2. ssh-keyscan を実行する

起動した socat 経由で ssh-keyscan を実行します。

ssh-keyscan -p 1234 localhost

取得された結果のホスト名は localhost になるため適宜読み替えてください。

3. socat プロセスを終了する

fg %1   # バックグラウンドジョブをフォアグラウンドに戻す
Ctrl+C  # 停止
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?