2016-12-14 6 views
1

各ステーションで公開鍵を生成して他のステーションにコピーすることによって、2つのステーション間でSSH接続を構成しました。これで、パスワードなしで1つのステーションから別のステーションに接続できるようになりましたが、sshに接続するためのbashスクリプトを作成したいのであれば、依然としてパスワードを要求します。スクリプトを実行した後でパスワードの入力を求められないようにするにはどうすればよいですか?bashスクリプトのSSHはパスワードを要求しますが、コマンドラインのsshは鍵で認証されます

編集:スクリプトを追加しました。私はstation1におり、station2(ホスト)に接続したいと思う。

#!/bin/bash 
ssh host 

EDIT2:station2名はホスト

である:コマンドライン

OpenSSH_5.9p1 Debian-5ubuntu1.1, OpenSSL 1.0.1 14 Mar 2012 
debug1: Reading configuration data /home/user/.ssh/config 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: /etc/ssh/ssh_config line 19: Applying options for * 
debug1: Connecting to host [IP] port 22. 
debug1: Connection established. 
debug1: identity file /home/user/.ssh/id_rsa type 1 
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048 
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048 
debug1: identity file /home/user/.ssh/id_rsa-cert type -1 
debug1: identity file /home/user/.ssh/id_dsa type -1 
debug1: identity file /home/user/.ssh/id_dsa-cert type -1 
debug1: identity file /home/user/.ssh/id_ecdsa type -1 
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1 
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1 
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH* 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr hmac-md5 none 
debug1: kex: client->server aes128-ctr hmac-md5 none 
debug1: sending SSH2_MSG_KEX_ECDH_INIT 
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY 
debug1: Server host key: ECDSA f5:6c:00:ed:78:ac:1d:79:dc:71:57:6f:f5:09:fe:3a 
debug1: Host 'host' is known and matches the ECDSA host key. 
debug1: Found key in /home/user/.ssh/known_hosts:2 
debug1: ssh_ecdsa_verify: signature correct 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: Roaming not allowed by server 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey 
debug1: Next authentication method: publickey 
debug1: Offering RSA public key: /home/user/.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 host ([IP]:Port). 
debug1: channel 0: new [client-session] 
debug1: Requesting [email protected] 
debug1: Entering interactive session. 
debug1: Sending environment. 

EDIT3からスクリプト

OpenSSH_5.9p1 Debian-5ubuntu1.1, OpenSSL 1.0.1 14 Mar 2012 
debug1: Reading configuration data /root/.ssh/config 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: /etc/ssh/ssh_config line 19: Applying options for * 
debug1: Connecting to host [IP] port 22. 
debug1: Connection established. 
debug1: permanently_set_uid: 0/0 
debug1: identity file /root/.ssh/id_rsa type -1 
debug1: identity file /root/.ssh/id_rsa-cert type -1 
debug1: identity file /root/.ssh/id_dsa type -1 
debug1: identity file /root/.ssh/id_dsa-cert type -1 
debug1: identity file /root/.ssh/id_ecdsa type -1 
debug1: identity file /root/.ssh/id_ecdsa-cert type -1 
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1 
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH* 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr hmac-md5 none 
debug1: kex: client->server aes128-ctr hmac-md5 none 
debug1: sending SSH2_MSG_KEX_ECDH_INIT 
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY 
debug1: Server host key: ECDSA f5:6c:00:ed:78:ac:1d:79:dc:71:57:6f:f5:09:fe:3a 
debug1: Host 'host' is known and matches the ECDSA host key. 
debug1: Found key in /root/.ssh/known_hosts:3 
debug1: ssh_ecdsa_verify: signature correct 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: Roaming not allowed by server 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey 
debug1: Next authentication method: publickey 
debug1: Trying private key: /root/.ssh/id_rsa 
debug1: Trying private key: /root/.ssh/id_dsa 
debug1: Trying private key: /root/.ssh/id_ecdsa 
debug1: No more authentication methods to try. 
Permission denied (publickey). 

2からssh -v出力

1))

+1

問題のスクリプトを入力してください。 – cmidi

+0

主に、スクリプトの出力に 'ssh -v'スイッチを指定してください。 * "私は1つのステーションから別のステーションにパスワードなしで接続することができます" * –

答えて

4

スクリプトはrootアカウントで実行されます:

debug1: Reading configuration data /root/.ssh/config 

だから、userアカウントのキーを使用しません。


スクリプトの実行方法はわかりません。

しかし、多分あなたはsusudoを使用して、それを実行することができます。

su - user -c /home/user/script.sh 
+1

"ole '"、 "スクリプトは別のユーザーバディーとして実行されています..."という問題があります。 –

2

あなたはこの

のようにテキストを追加し、この

ssh -i /path/to/key/file [email protected] 

またはあなたのの〜/ .ssh/configの中を使用することができます

Host foobar 
    HostName 1.2.3.4 
    Port 22 
    User root 
    IdentityFile ~/.ssh/id_rsa 

今すぐログインすることができます。

ssh foobar 
関連する問題