日期:2014-05-16  浏览次数:20677 次

Linux ssh server配置rsa登陆认证

原理:密钥相当于一把钥匙,而公钥就相当于一把门锁,我们当然是拿着钥匙去开锁,同样的道理,我们密钥放在本地服务器,也就是客户机A,把公钥放在远程服务器,也就是远端主机B,那么我们就可以从客户机A ssh免密码登陆远端主机B.

1、生成密匙
[root@www.linuxidc.com .ssh]#
ssh-keygen-t rsa
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:
e4:9a:47:a7:b4:8a:0b:98:07:b8:70:de:6b:16:2c:0c
root@www.linuxidc.com


2、将 /root/.ssh/id_rsa.pub改名为/root/.ssh/authorized_keys
[root@www.linuxidc.com .ssh]#
mv/root/.ssh/id_rsa.pub /root/.ssh/authorized_keys


3、将私钥id_rsa拷贝到远程客户端
1)如果远程客户端是linux,拷贝到远程客户端/root/.ssh/即可
2)putty
作为远程客户端
putty
不能识别直接从服务器拷贝来的私钥,需要使用puttygen.exe进行格式转换
(1)
、打开puttygen.exe --> Conversions --> Import Key
(2)
、选择拷贝过来的私钥文件id_rsa
(3)
Save private key->id_rsa.ppk(保存私钥)

4、打开