配置环境:A机器:ip 192.168.1.123
B机器:ip 192.168.1.122
配置目的:A机器提供SSH服务,B机器不用输入A机器密码登陆到A机器提供的SSH服务上去
1、在A机器下生成公钥和秘钥对:
chenlb@A
~
]$ ssh
-
keygen
-
t rsa
-
P
''
-P表示密码,-P '' 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车。
它在/home/chenlb下生成.ssh目录,.ssh下有id_rsa和id_rsa.pub。
2.把A机下的id_rsa.pub复制到B机下,在B机的.ssh/authorized_keys文件里,用scp复制。
3.B机把从A机复制的id_rsa.pub添加到.ssh/authorzied_keys文件里。
# cat id_rsa.pub >> .ssh/authorized_keys
# chmod 600 .ssh/authorized_keys
4.A机登录B机。
# ssh
192.168
.
1.181
The authenticity of host ' 192.168.1.123 (192.168.1.123) ' can ' t be established.
RSA key fingerprint is 00 :a6:a8: 87 :eb:c7: 40 : 10 : 39 :cc:a0:eb: 50 :d9:6a:5b.
Are you sure you want to continue connecting (yes / no)? yes
Warning: Permanently added ' 192.168.1.123 ' (RSA) to the list of known hosts.
Last login: Thu Jul 3 0 9 : 53 : 18 2008 from chenlb
#
The authenticity of host ' 192.168.1.123 (192.168.1.123) ' can ' t be established.
RSA key fingerprint is 00 :a6:a8: 87 :eb:c7: 40 : 10 : 39 :cc:a0:eb: 50 :d9:6a:5b.
Are you sure you want to continue connecting (yes / no)? yes
Warning: Permanently added ' 192.168.1.123 ' (RSA) to the list of known hosts.
Last login: Thu Jul 3 0 9 : 53 : 18 2008 from chenlb
#
小结:登录的机子可有私钥,被登录的机子要有登录机子的公钥。这个公钥/私钥对一般在私钥宿主机产生。上面是用rsa算法的公钥/私钥对,当然也可以用dsa(对应的文件是id_dsa,id_dsa.pub)
转载于:https://blog.51cto.com/shouhouzhe/1376922