服务器之间ssh无秘钥认证失败原因

环境介绍:

A主机10.0.54.199    hostname:localhost

B主机10.0.54.181    hostname:ractest1


1、A主机创建公钥和秘钥

[root@localhost ~]# 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:
bb:76:48:de:68:bd:1b:2d:62:d6:a6:ee:8b:f4:c2:d6 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|        S        |
|        .o .     |
|     ..+=== .    |
|     .+=E=+o     |
|     ..*Booo     |
+-----------------+

2、查看公钥秘钥

[root@localhost ~]# ll .ssh/
total 12
-rw------- 1 root root 1675 Dec  7 18:41 id_rsa
-rw-r--r-- 1 root root  408 Dec  7 18:41 id_rsa.pub
-rw-r--r-- 1 root root  393 Dec  7 18:42 known_hosts


3、拷贝A主机公钥到B主机root账户下,输入B主机密码

[root@localhost ~]# ssh-copy-id [email protected]
The authenticity of host '10.0.54.181 (10.0.54.181)' can't be established.
RSA key fingerprint is f1:68:d6:d7:c8:94:4e:34:1c:42:96:86:98:5d:12:93.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.54.181' (RSA) to the list of known hosts.
[email protected]'s password:
Now try logging into the machine, with "ssh '[email protected]'", and check in:

  .ssh/authorized_keys

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


4、登录验证

[root@localhost ~]# ssh [email protected]
Last login: Tue Dec 15 15:39:11 2015 from 10.0.54.199
[root@ractest1 ~]# w
 16:32:33 up 27 days, 8 min,  2 users,  load average: 0.06, 0.07, 0.01
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/1    10.0.54.70       13:28   46:56   0.06s  0.06s -bash
root     pts/2    10.0.54.199      16:32    0.00s  0.00s  0.00s w


5、如果登录不上去请在B主机上查看root目录权限,如果权限是700,750都是可以登录上去的,但是权限是775,此时A主机是不能无秘钥登录必须输入密码才可以登录,切记。被这个问题搞了一上午,写下来告诉大家。

[root@ractest1 ~]# ll -d /root/
drwxr-x--- 18 root root 4096 Dec 15 13:28 /root/

你可能感兴趣的:(ssh-keygen,ssh认证,ssh无秘钥认证失败)