linuxserver之间的无密码SSH连接要求输入密码

时间:2014-07-21 18:26:33

标签: linux ssh rsa dsa

我正在尝试在两个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,并且密钥文件中没有密码设置。

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

我通过在本地计算机上运行此命令(生成密钥后)解决了问题:

$ ssh-add

答案 1 :(得分:0)

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

root@client:~# ssh central@server

您省略了-i private-key-file参数,但未在.ssh/config中为该连接定义一个参数。