2014年8月5日星期二

Linux_075:实现SSH无密码登录

运行环境:RHEL 6.5  + CentOS 6.0

每次使用ssh从RHEL 6.5 登录到 CentOS 6.0时,都需要输入密码,本文介绍如何
ssh-keygen + ssh-copy-id 实现ssh无密码登录。

假设你知道CentOS 6.0的root账户的密码,在RHEL 6.5上执行如下命令:

1. # ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:
52:83:a5:c5:31:99:26:a2:be:19:2e:7c:69:ad:5a:d9 root@dhcp-192-21.pek.redhat.com
The key's randomart image is:
+--[ RSA 2048]----+
|       .=+       |
|    . .==.       |
|   . .ooo        |
|  .    . .       |
| .    . S        |
|  o o  .         |
|.. *oE           |
|..=+ .           |
| o+..            |
+-----------------+

 2. ssh-copy-id root@123.125.211.39
这里假设123.125.211.39是CentOS 6.5的IP地址,根据提示输入CentOS 6.5的root账户的密码。
root@123.125.211.39's password:
Now try logging into the machine, with "ssh 'root@123.125.211.38'", and check in:

  .ssh/authorized_keys

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

3. # ssh 123.125.211.38
应该能够直接登录到CentOS 6.5,无需输入密码。

如果是其它用户,只需要把root改成相应用户的名称。
比如:ssh-copy-id test@123.125.211.39 和 ssh test@123.125.211.39

参考文献:
1. http://blog.csdn.net/pennyliang/article/details/8556662
2. http://blog.chinaunix.net/uid-26284395-id-2949145.html
3. http://jingyan.baidu.com/article/2fb0ba4043124a00f2ec5f0f.html

没有评论: