0

我正在尝试在两个 linux 机器之间创建一个无密码连接(使用密钥)。我之前已经做过 20 或 30 次,但这是它第一次与我抗争并在全新安装的 Centos 7 上尝试它。我创建了密钥,ssh-copy-id 将其重新创建,它看起来很开心。当我登录时,它仍然要求输入密码。

root@client:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
(client-key) root@client
The key's randomart image is:
+--[ RSA 2048]----+
|              E. |
|            . .  |
|             o   |
|            .  +.|
|      o S   ..o =|
|     o . . . ooo.|
|      . .  ..=+ .|
|       .   .=. . |
|        ..oo.oo  |
+-----------------+
root@client:~# ssh-copy-id -i .ssh/id_rsa.pub central@server
central@server's password:
Now try logging into the machine, with "ssh 'central@server'", and check in:

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

root@client:~# ssh central@server
central@server's password: (password entered at this point to make sure I had it correct)
Last login: Mon Jul 21 14:06:43 2014
[central@server ~]$

我发现许多提到检查 .ssh 文件夹和 authorized_keys 文件的权限,并尝试了各种不同的组合。我已经清除了两台服务器上的 .ssh 文件夹并从头开始。SElinux 在两个盒子上都被禁用,并且任何时候都没有在密钥文件上设置密码。

有什么想法吗?

4

2 回答 2

2

我通过简单地在本地机器上运行这个命令(在生成密钥之后)解决了这个问题:

$ ssh-add
于 2014-07-21T18:45:40.290 回答
0

实际错误是您在部署公钥后尝试登录时:

root@client:~# ssh central@server

您省略了-i private-key-file参数并且没有.ssh/config为该连接定义一个。

于 2014-07-21T19:44:48.960 回答