web-dev-qa-db-ja.com

plinkを使用してサーバーホストキーをキャッシュに自動保存する

外部サーバーから情報を取得するためにplinkを使用してコマンドを発行しようとしています。これらのplinkコマンドは、ユーザーからの入力を期待しないバイナリから実行されることに注意してください。このエラーメッセージを上書きしてプログラム出力を続行できるフラグはありますか?

The server's Host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 **:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**
If you trust this Host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this Host, press Return to abandon the
connection.
Store key in cache? (y/n)

ありがとうございました!

21
Tad Oh

スクリプトを前に追加してみてください:

echo y | plink -ssh root@REMOTE_IP_HERE "exit"

これは、キャッシュにStoreキーを取得するときに、y文字をstdinからplinkにパイプしますか? (y/n)プロンプト。ユーザーの入力を必要とせずに、それ以降のすべてのplinkコマンドが通過できるようにします。 exitコマンドは、SSHセッションが確立された後に閉じ、次のplinkコマンドを実行できるようにします。

外部サーバーのUnix時間をローカルファイルに書き込むスクリプトの例を次に示します。

echo y | plink -ssh root@REMOTE_IP_HERE "exit"
plink -ssh root@REMOTE_IP_HERE "date -t" > remote_time.tmp

パイプラインリファレンスhttp://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html

20
Daniel Li

受け入れられた答えは「受け入れ可能」ですが、安全ではありません。最善の方法は、plinkするホストキーを指定して、任意の Man-In-the-Middle 攻撃を防ぐことです。

plink -hostkey aa:bb:cc... root@REMOTE_IP_HERE [...]