Ticket #35106

SSH: Permission denied (publickey).

Open Date: 2015-05-03 12:26 Last Update: 2015-05-07 20:46

Reporter:
Owner:
(None)
Status:
Closed
Component:
MileStone:
(None)
Priority:
5 - Medium
Severity:
5 - Medium
Resolution:
Accepted
File:
None

Details

以前登録していた鍵でログインできなくなり、何度か鍵の更新を試みたのですが、 うまくいかないようです。よろしくお願いします。

user@cfw7:~$ ssh -v tkamogashira@shell.sourceforge.jp -i .ssh/id_rsa
OpenSSH_6.7p1 Debian-5, OpenSSL 1.0.1k 8 Jan 2015
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 shell.sourceforge.jp [202.221.179.26] port 22.
debug1: Connection established.
debug1: identity file .ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file .ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Debian-5
debug1: Remote protocol version 1.99, remote software version OpenSSH_5.5p1 Debian-6+squeeze5
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze5 pat OpenSSH_5* compat 0x0c000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr umac-64@openssh.com none
debug1: kex: client->server aes128-ctr umac-64@openssh.com none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<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 15:22:46:69:9f:ac:14:68:8a:be:f1:e4:29:7c:a9:51
debug1: Host 'shell.sourceforge.jp' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
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: .ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
user@cfw7:~$ 

Ticket History (3/12 Histories)

2015-05-03 12:26 Updated by: tkamogashira
  • New Ticket "SSH: Permission denied (publickey)." created
2015-05-07 12:29 Updated by: ishikawa
  • Resolution Update from None to Accepted
Comment

tkamogashira への返信

ログを確認しましたが特に異常な点は見受けられません(正常に正しいIPアドレスに接続して 正しく認証を行おうとして失敗しているログに見えます) また、念のためサーバ側の状態も確認しましたが こちらも特に異常は見受けられません。 sf.jp の shell サーバ上に登録されている該当アカウントの ssh のキーは 2015-05-03 の 11:56 に正常に更新されています。

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: .ssh/id_rsa

ここまでログは特に問題がないように見えますし、正常に key auth を行おうとして います。ここでサーバ側に送った key が サーバ側に登録してあるキーと同一であれば、 このあと key auth が成功して(サーバが key をaccept して)

debug1: Server accepts key: pkalg ssh-rsa blen 149
debug1: Authentication succeeded (publickey).

といったログが出力されるはずですが、そのログがないことから単純に利用しようとして いるssh キーが間違っている等で key auth に失敗しているように見受けられます。

user@cfw7:~$ ssh -v tkamogashira@shell.sourceforge.jp -i .ssh/id_rsa

としていて、カレントワーキングディレクトリがどこなのかはっきりしませんが、 user というアカウントのホームディレクトリ である /home/user だと仮定すると この場合、認証には -i のあとに指定されているファイル /home/user/.ssh/id_rsa (の公開鍵 /home/user/.ssh/id_rsa.pub) が使用されますので、この鍵が正常な (登録した)キーと同一なのを確認してください。

  • 上記のオプション指定ですと相対パス指定になっていますので カレントワーキングディレクトリ以下の .ssh/id_rsa が利用されます。カレントワーキングディレクトリによっては意図しないキーファイルを利用してしまう可能性がありますので、/home/user/.ssh/id_rsa のように 絶対パスで絶対パスで指定してみてください(あるいは -i オプションの指定がなければ user アカウントの $HOME の .ssh 以下にあるキーが利用されます)
  • ssh-keygen -l して key file を指定すると key の fingerprint が表示できます。sf.jp のサーバサイトに登録されている該当アカウントの public key の fingerprint は以下になっていますので 一致するか確認してください(識別子としてメアドが書かれていましたので XXX で 伏せてあります)
2048 51:d9:34:d7:ef:cb:34:e8:e4:cb:a9:20:22:68:4f:e8  XXXXXXXXXXXX (RSA)
2015-05-07 12:29 Updated by: ishikawa
  • Component Update from (None) to シェルサーバ
2015-05-07 16:16 Updated by: tkamogashira
Comment

お忙しい中申し訳ありません。

鍵についてはチェックしましたが、あっているようでした。 SSHのバージョンも最新と思います。他に問題になる箇所が思い浮かばないのですが、 ネットワークの問題だとそもそもコネクションできないと思うのですが、 こんなことは初めてで、申し訳ありません。

ii  libssh2-1:amd64                                             1.4.3-4.1                           amd64        SSH2 client-side library
ii  openssh-client                                              1:6.7p1-5                           amd64        secure shell (SSH) client, for secure access to remote machines
user@cfw7:~$ echo | ssh-keygen -l
Enter file in which the key is (/home/user/.ssh/id_rsa): 2048 51:d9:34:d7:ef:cb:34:e8:e4:cb:a9:20:22:68:4f:e8 .ssh/id_rsa.pub (RSA)
user@cfw7:~$ ssh -i /home/user/.ssh/id_rsa tkamogashira@shell.sourceforge.jp -v
OpenSSH_6.7p1 Debian-5, OpenSSL 1.0.1k 8 Jan 2015
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 shell.sourceforge.jp [202.221.179.26] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Debian-5
debug1: Remote protocol version 1.99, remote software version OpenSSH_5.5p1 Debian-6+squeeze5
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze5 pat OpenSSH_5* compat 0x0c000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr umac-64@openssh.com none
debug1: kex: client->server aes128-ctr umac-64@openssh.com none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<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 15:22:46:69:9f:ac:14:68:8a:be:f1:e4:29:7c:a9:51
debug1: Host 'shell.sourceforge.jp' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
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: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
user@cfw7:~$
2015-05-07 16:49 Updated by: ishikawa
Comment

tkamogashira への返信

お忙しい中申し訳ありません。 鍵についてはチェックしましたが、あっているようでした。 SSHのバージョンも最新と思います。他に問題になる箇所が思い浮かばないのですが、 ネットワークの問題だとそもそもコネクションできないと思うのですが、

はい、ネットワーク的なトラブルではありません。ssh のプロコトル上での問題です (問題というか 認証が失敗しているだけです)

こんなことは初めてで、申し訳ありません。 {{{ ii libssh2-1:amd64 1.4.3-4.1 amd64 SSH2 client-side library ii openssh-client 1:6.7p1-5 amd64 secure shell (SSH) client, for secure access to remote machines }}} {{{ user@cfw7:~$ echo | ssh-keygen -l Enter file in which the key is (/home/user/.ssh/id_rsa): 2048 51:d9:34:d7:ef:cb:34:e8:e4:cb:a9:20:22:68:4f:e8 .ssh/id_rsa.pub (RSA)

うーん ちょっとそうなってくると こちらでも 理由が思い当たりませんが...

  • -v ではなく -vvv と指定して verbosity を最大まであげた場合、ログの中になにかヒントとなるようなものが記録されないでしょうか?
  • id_rsa と id_rsa.pub の組み合わせはちゃんと正しいでしょうか? 以下の手順で確認できるかと思います。

ssh-keygen に -y オプションを渡して 秘密鍵を指定すると 対応する公開鍵が stdout に吐き出されますので これをどこかに保存して fingerprint を比較してみてください。

$ ssh-keygen -y -f /home/user/.ssh/id_rsa > /tmp/pubkey
$ ssh-keygen -l -f /tmp/pubkey

この ssh-keygen -l の結果が 51:d9:34:d7:ef:cb:34:e8:e4:cb:a9:20:22:68:4f:e8 に一致しないようなら、 なんらかの誤操作で private key と public key の組み合わせがおかしくなってしまっています (間違った public key がファイルに記録されています)

2015-05-07 17:57 Updated by: tkamogashira
Comment

度々申し訳ありません。 鍵を再度試して見ましたが、ペアは合っているようでした。同じ鍵でネットワーク内の 他のマシンの~/.ssh/authorized_keysでSSHを試したところ、それではうまくいきました。 ssh-agentは見た目上はうごいているようです。 sf.jpに新たに別のアカウントを作って試してみる方が良いでしょうか?

user@cfw7:~$ ssh-keygen -y -f /home/user/.ssh/id_rsa > /tmp/pukey
Enter passphrase: 
user@cfw7:~$ ssh-keygen -l -f /tmp/pubkey
2048 51:d9:34:d7:ef:cb:34:e8:e4:cb:a9:20:22:68:4f:e8 /tmp/pubkey (RSA)
user@cfw7:~$ ssh -l tkamogashira shell.sourceforge.jp -i /home/user/.ssh/id_rsa -vvv
OpenSSH_6.7p1 Debian-5, OpenSSL 1.0.1k 8 Jan 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to shell.sourceforge.jp [202.221.179.26] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.7p1 Debian-5
debug1: Remote protocol version 1.99, remote software version OpenSSH_5.5p1 Debian-6+squeeze5
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze5 pat OpenSSH_5* compat 0x0c000000
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "shell.sourceforge.jp" from file "/home/user/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/user/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-dss-cert-v00@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: mac_setup: setup umac-64@openssh.com
debug1: kex: server->client aes128-ctr umac-64@openssh.com none
debug2: mac_setup: setup umac-64@openssh.com
debug1: kex: client->server aes128-ctr umac-64@openssh.com none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 1493/3072
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 15:22:46:69:9f:ac:14:68:8a:be:f1:e4:29:7c:a9:51
debug3: load_hostkeys: loading entries for host "shell.sourceforge.jp" from file "/home/user/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/user/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: load_hostkeys: loading entries for host "202.221.179.26" from file "/home/user/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/user/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys
debug1: Host 'shell.sourceforge.jp' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:1
debug2: bits set: 1533/3072
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/user/.ssh/id_rsa (0x7fa7627e4090), explicit
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
user@cfw7:~$ 
2015-05-07 18:09 Updated by: ishikawa
Comment

tkamogashira への返信

度々申し訳ありません。 鍵を再度試して見ましたが、ペアは合っているようでした。同じ鍵でネットワーク内の 他のマシンの~/.ssh/authorized_keysでSSHを試したところ、それではうまくいきました。 ssh-agentは見た目上はうごいているようです。

ssh-agent が動いているということであれば ssh-add -l すると agent がキャッシュしている キーの finger print が 表示できます。この fingerprint が一致しているかも確認してください。

2015-05-07 18:28 Updated by: tkamogashira
Comment

RSAの方は登録しているのと同じfingerprintでした。

teru@cfw7:~$ ssh-add -l
2048 51:d9:34:d7:ef:cb:34:e8:e4:cb:a9:20:22:68:4f:e8 /home/teru/.ssh/id_rsa (RSA)
1024 9d:5b:48:77:21:ef:4f:f3:93:70:21:16:0f:1e:10:4e dsa w/o comment (DSA)

2015-05-07 18:58 Updated by: ishikawa
Comment

tkamogashira への返信

RSAの方は登録しているのと同じfingerprintでした。 {{{ teru@cfw7:~$ ssh-add -l 2048 51:d9:34:d7:ef:cb:34:e8:e4:cb:a9:20:22:68:4f:e8 /home/teru/.ssh/id_rsa (RSA) 1024 9d:5b:48:77:21:ef:4f:f3:93:70:21:16:0f:1e:10:4e dsa w/o comment (DSA) }}}

確認しているアカウントが違う/ファイルのパスも異なるようですが (ここまでのログでは user となっていました)大丈夫ですか?

2015-05-07 19:29 Updated by: ishikawa
Comment

サーバ側での挙動の情報をもう少し集めるために 現在一時的にサーバ側のログレベルをあげてあります。

再度ログインを試していただき、ログインを試みてみた時刻をお知らせください。

2015-05-07 19:40 Updated by: ishikawa
Comment

サーバ側で一箇所問題を発見したので先ほど(2015/05/07 19:35 JST ころ) 修正しました。

これでログインできるのではないかと思われますが いかがでしょうか?

2015-05-07 20:46 Updated by: tkamogashira
  • Status Update from Open to Closed
  • Ticket Close date is changed to 2015-05-07 20:46
Comment

大変お手数をおかけし、申し訳ございませんでした。 いくつか環境を変えながら試していたのですが、 どこでも問題なく入れるようになりました。 誠にありがとうございました。

Attachment File List

No attachments

Edit

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Login