ssh:id_rsa不起作用,但是如果我重命名,它将起作用


10

我的〜/ .ssh文件夹中有这个id_rsa。但是它只是不进行身份验证。如果我将其复制并重命名为非id_rsa的任何名称,它将起作用。

[qfan@mycomputer .ssh]$ ls -al id_rsa id_rsa_good
-rw------- 1 qfan qfan 1766 Dec  3 18:35 id_rsa
-rw------- 1 qfan qfan 1766 Nov 20 19:43 id_rsa_good
[qfan@mycomputer .ssh]$ sha1sum id_rsa id_rsa_good
8cc7f68170038b184bba0541be7d105bb36f7d11  id_rsa
8cc7f68170038b184bba0541be7d105bb36f7d11  id_rsa_good
[qfan@mycomputer .ssh]$ ssh localhost -i id_rsa
qfan@localhost's password: 

[qfan@mycomputer .ssh]$ ssh localhost -i id_rsa_good
Enter passphrase for key 'id_rsa_good': 
Last login: Tue Dec  3 18:46:46 2013 from 127.0.0.1
[qfan@mycomputer ~]$ exit
logout
Connection to localhost closed.

请注意,“ ssh localhost -i id_rsa”失败,并且ssh开始要求常规密码登录。

我使用了-vvv,这是日志的区别:

[qfan@mycomputer .ssh]$ ssh localhost -i id_rsa_good -vvv 2> log1_good.txt
Enter passphrase for key 'id_rsa_good': 

[qfan@mycomputer .ssh]$ ssh localhost -i id_rsa -vvv 2> log2_bad.txt
qfan@localhost's password: 

[qfan@mycomputer .ssh]$ diff log1_good.txt log2_bad.txt 
7c7
< debug3: Not a RSA1 key file id_rsa_good.
---
> debug3: Not a RSA1 key file id_rsa.
41c41
< debug1: identity file id_rsa_good type -1
---
> debug1: identity file id_rsa type 1
81,82c81,82
< debug2: dh_gen_key: priv key bits set: 126/256
< debug2: bits set: 533/1024
---
> debug2: dh_gen_key: priv key bits set: 127/256
> debug2: bits set: 503/1024
90c90
< debug2: bits set: 506/1024
---
> debug2: bits set: 539/1024
103c103
< debug2: key: id_rsa_good ((nil))
---
> debug2: key: id_rsa (0x7f953ea96f90)
136,138c136,145
< debug1: Trying private key: id_rsa_good
< debug1: PEM_read_PrivateKey failed
< debug1: read PEM private key done: type <unknown>
---
> debug1: Offering public key: id_rsa
> debug3: send_pubkey_test
> debug2: we sent a publickey packet, wait for reply
> debug3: Wrote 368 bytes for a total of 1477
> debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
> debug2: we did not send a packet, disable method
> debug3: authmethod_lookup password
> debug3: remaining preferred: ,password
> debug3: authmethod_is_enabled password
> debug1: Next authentication method: password
[qfan@mycomputer .ssh]$ 

我还尝试从密钥文件中删除密码,但是如果命名为id_rsa,该密码仍然无法使用。

那么,那里出了什么问题?

- - - -编辑 - - - -

[qfan@mycomputer .ssh]$ file id_rsa
id_rsa: ASCII text
[qfan@mycomputer .ssh]$ cat id_rsa |head -n2
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED

1
您确定文件包含RSA密钥吗?看起来好像当它命名为id_rsa时ssh假定它是rsa密钥(类型1),但是当您将其命名为id_rsa_good时,它并不确定(类型-1)。
mfarver 2013年

1
您可以运行file id_rsa并让我们看到输出吗?如果不是非常喜欢的东西id_rsa: PEM RSA private key,那么mfarver可能很有意义!
MadHatter

它是文本文件:[qfan @ mycomputer .ssh] $文件id_rsa id_rsa:ASCII文本[qfan @ mycomputer .ssh] $ cat id_rsa | head -n2 ----- BEGIN RSA PRIVATE KEY ----- Proc-Type: 4,Encrypted
Qi Fan

Answers:


12

找到了原因。我id_rsa.pub在同一.ssh文件夹中的文件是属于另一个身份文件的公用密钥。如果id_rsa.pub不匹配,id_rsa,它将自动失败。删除或移动id_rsa.pub文件即可完成id_rsa工作。


1
我很想知道为什么会这样……
David Resnick

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.