ssh-keygen 用来生成ssh登录的key,可以使我们以后登录远程主机时无需再输入远程主机的key.
具体使用方法如下:
例如我们有两台主机:
A:192.168.0.1 B:192.168.0.2
当我们需要用主机A登录远程主机B时,我们在主机A上输入:
一、# ssh-keygen -t rsa
会产生如下的信息:
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ->输入key文件的名称
Enter passphrase (empty for no passphrase): ->输入使用key时的密码,注意这里不是远处服务器的密码,
只是你使用sshkey时需要输入的密码,
建议不输入(如果要输入这个密码还不如直接输入
远处主机的密码:))
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:
11:ae:00:bd:92:bc:70:f8:4b:cb:47:06:7f:e2:73:21 root@xxxxxx
二、# scp id_rsa.pub 192.168.0.2:/root/.ssh/
三、ssh 192.168.0.2 ->登录远程主机B
root@192.168.0.2's password: ->输入密码
四、 # cd /root/.ssh ->进入到key目录
# cat id_rsa.pub >> authorized_keys
五、#chmod 700 .ssh
#chmod 600 authorized_keys
六、#exit -> 推出远程B服务器
七、#service sshd restart ->重新启动ssh服务
八、#ssh 192.168.0.2 ->远程登录到B测试下吧:)