5
7

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 5 years have passed since last update.

踏み台サーバーを超えていけ

Posted at

踏み台サーバーを踏み倒すときに使えるコマンド

ProxyCommand:文字の通りにプロキシ上で動作するコマンドを指定できる

scp接続

$ scp -o 'ProxyCommand ssh -A fumidai.co.jp nc %h %p' hoge,txt honban.co.jp:/home/hogehoge

本来の目的:honban.co.jpにhoge.txtをscpする
ProxyCommandがはたらき、踏み台サーバーを通り越してscp接続することができる

利点

  • コピーが1回しか動かないので踏み台を通すより早い
  • 踏み台サーバーに余計なファイルが残らない
  • scpコマンドが使えない踏み台サーバーを超えられる
  • はやい

ssh接続

$ ssh -oProxyCommand='ssh -W %h:%p fumidai.co,jp' honban.co.jp

2段以上の多段接続

~/.ssh/configに接続情報を記録しておくことで何段階でも多段接続することができます

$ vi ~/.ssh/config

Host fumidai-first
    HostName fumidai-first.co.jp
    User hogehoge
    IdentityFile ~/.ssh/id_rsa

Host fumidai-second
    HostName fumidai-second.co.jp
    User hogehoge
    IdentityFile ~/.ssh/id_rsa
    ProxyCommand ssh fumidai-first -W %h:%p

Host honban
    HostName honban.co.jp
    User hogehoge
    IdentityFile ~/.ssh/id_rsa
    ProxyCommand ssh fumidai-second -W %h:%p

このように設定しておけば「ssh honban」で本番に接続することができます。

5
7
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
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?