7
9

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.

多段SSH環境かつパスワード認証でcookしたいとき

Posted at

About

何らかの理由で公開鍵が登録されておらず、パスワード認証でcookしないといけない場合の対応です。

Environment

ローカルマシン --- 踏み台 --- 対象ホスト

※ 全てパスワード認証

対応前

  • chefでcookする際に何度もパスワードを聞かれてしまいました。
dev@192.168.1.2's password:
dev@10.0.0.2's password:
Uploading the kitchen...
dev@192.168.1.2's password:
dev@10.0.0.2's password:
Killed by signal 1.
dev@192.168.1.2's password:
dev@10.0.0.2's password:
Killed by signal 1.
dev@192.168.1.2's password:
dev@10.0.0.2's password:
Killed by signal 1.
  • その時の~/ssh/config
Host target
 HostName 10.0.0.2
 User test
 UserKnownHostsFile /dev/null
 StrictHostKeyChecking no
 ProxyCommand ssh -CW %h:%p bastion
 LogLevel FATAL

Host bastion
  HostName 192.168.1.2
  User test
  ForwardAgent yes

対応後

  • ~/.ssh/configを修正する
Host target
 HostName 10.0.0.2
 User test
 UserKnownHostsFile /dev/null
 StrictHostKeyChecking no
 ProxyCommand ssh -CW %h:%p bastion
 LogLevel FATAL
 ControlMaster auto
 ControlPath ~/.ssh/mux-%r@%h:%p
 ControlPersist 30m

Host bastion
  HostName 192.168.1.2
  User test
  ForwardAgent yes
  ControlMaster auto
  ControlPath ~/.ssh/mux-%r@%h:%p
  ControlPersist 30m

ControlMasterはマスターのセッションを一つはり、それを使いまわす仕組みのようです。最初のログインの際にだけパスワードが聞かれ、その後はそのセッションを使いまわします。

公開鍵が登録されていないサーバに対し初回cookする時などに使うと便利かなと思います。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?