web-dev-qa-db-ja.com

SSH公開鍵が機能しない

私はこれを解決するために数時間を費やしましたが、どこにも行きませんでした。

サーバーはCentOS6を実行しており、OpenSSHを使用しています。クライアントもOpenSSHを実行しています。

ssh-keygen -t rsaを使用してクライアント(PC)で公開鍵を作成し、ssh-copy-id user@Hostを使用してサーバーに送信しました。

その後、(パスワードを使用して)サーバーにログオンし、ファイルがそこにあり、いくつかのものが含まれていることを確認しました。アクセス許可を600に変更しました CentOS Wikiに記載されています

その後、もう一度サーバーにSSHで接続しようとしましたが、パスワードを入力する必要がありました。詳細オプションを使用した出力は次のとおりです。

user@hostname ~ $ ssh censored@censored -v
OpenSSH_6.0p1 Debian-3ubuntu1, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to censored [censored] 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.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0p1 Debian-3ubuntu1
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: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server Host key: RSA 92:67:19:72:5f:ed:b1:a3:14:7f:f3:82:e2:4d:ef:16
debug1: Host 'censored' is known and matches the RSA Host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
debug1: ssh_rsa_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,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Next authentication method: password
censored@censored's password: 

サーバーのSSHD構成で、コメントを外し、次のようないくつかのオプションを変更しました。

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile /home/%u/.ssh/authorized_keys

サーバーでssh-addを実行しようとしましたが、ssh-add -lを実行しても、何も表示されません。

どんな助けでも本当にありがたいです。

編集:問題はクライアント側にある可能性があります。 Raspberry Piでこれを設定し、接続時にもこれを取得しようとしました。

user@hostname ~ $ ssh pi@raspberrypi -v
OpenSSH_6.0p1 Debian-3ubuntu1, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to raspberrypi [192.168.1.70] 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_6.0p1 Debian-3
debug1: match: OpenSSH_6.0p1 Debian-3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0p1 Debian-3ubuntu1
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 72:e3:36:15:72:c9:ca:9f:66:a9:d5:3f:88:d0:7a:e7
debug1: Host 'raspberrypi' is known and matches the ECDSA Host key.
debug1: Found key in /home/user/.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,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
Agent admitted failure to sign using the key.
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/user/.ssh/id_dsa
debug1: Trying private key: /home/user/.ssh/id_ecdsa
debug1: Next authentication method: password
pi@raspberrypi's password: 
3
user183714

あるいは単に:

restorecon -R -v /root/.ssh
2
Tommek

リストされている手順では、公開鍵をauthorized_keysファイルに追加したことを示唆するものは何も表示されません。

サーバーで、次のことを試してください。

cat /path/to/key.pub >> ~/.ssh/authorized_keys{,2}

シェル拡張は、うまくいけば両方のファイルを実行するはずです。

ローカルでは、600のパーミッションになる~/.ssh/configファイルを含める必要があるかもしれません。それが必要だと思われる場合は、例として私の投稿をします。その中で、ユーザー名と使いやすいホスト名を指定できます(user@exampleではなく、sshが選択した名前になります)

また、ローカルキーは~/.sshにありますか?

1
nerdwaller