SSHでパスワードの入力を求められたらスクリプトを終了する

SSHでパスワードの入力を求められたらスクリプトを終了する

XYZサーバーからABCサーバーにSSHを実行する必要があるシナリオを実装しようとしています。シームレスなパスワードのないログイン用に公開鍵がすでに設定されています。今、パスワードを求めるSSHコマンドを見つけたら、スクリプトを終了したいと思います。これは公開鍵が設定されていないことを意味します。

ssh -o ConnectTimeout=10 user@ABC <<HERE
----- doing some stuff here----
HERE

出力 -

Password:

スクリプトはXYZにあります。 XYZで実行し、SSH ABCを試してください。パスワードの入力を求められたら、メッセージを印刷してスクリプトを終了します。

ベストアンサー1

努力する

ssh -o BatchMode=yes

~によるとman 5 ssh_config

バッチモード

       If set to “yes”, passphrase/password querying will be disabled.
         In addition, the ServerAliveInterval option will be set to 300
         seconds by default.  This option is useful in scripts and other
         batch jobs where no user is present to supply the password, and
         where it is desirable to detect a broken network swiftly.  The
         argument must be “yes” or “no”.  The default is “no”.

おすすめ記事