
ここにsshに小さな問題があります。
2台のコンピュータ間でsshにいくつかのキーが設定されており、パスワードなしで端末からsshを介してログインできます。
SSHを介してリモートサーバーにコマンドを送信するシェルスクリプトを作成しようとしています。スクリプトを実行すると、コマンドを実行する前に常にSSHパスワードを要求されます。端末を介したパスワードレスログインのように、スクリプトでSSHログインを機能させるにはどうすればよいですか?
ssh user@remoteMachine が「何かをする」のようなスクリプトでは、端末のコマンドが正しく実行されます。
(編集)詳細なフラグの違い
スクリプト:
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/remote/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/remote/.ssh/id_dsa
debug1: Trying private key: /home/remote/.ssh/id_ecdsa
debug1: Next authentication method: password
[email protected]'s password:
端末
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/remote/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.1.4 ([192.168.1.4]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_GB.UTF-8
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic i686)
スクリプトはただ
#/usr/bin/bash
ssh [email protected] 'touch ~/test'
スクリプトを実行可能にして使用しています。
./script
答え1
コンピュータにパッケージをインストールsshpass
した後、リモートでコマンドを実行できます。
#!/bin/bash
SCRIPT='
#Your commands
'
sshpass -p<pass> ssh -o 'StrictHostKeyChecking no' -p <port> user@host "$SCRIPT"
sshpass -f<file>
また、すべてのサーバーのパスワードファイルを使用できます。したがって、SSHを作成して自動化するループを作成できます。