[root@WebServer3 ~]# 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:
a2:1d:43:32:26:06:68:48:d5:62:16:6d:a2:c7:53:8c root@WebServer3
输入命令后直接都按回车就行。
第一提示是密钥保存位置
Enter file in which to save the key (/root/.ssh/id_rsa):
直接回车保存到默认地方 /root/.ssh/id_rsa
第二个提示是输入一个不同于你的password的密码。直接按回车,不输入密码,保持密码为空。
其中公共密钥保存在 ~/.ssh/id_rsa.pub
私有密钥保存在 ~/.ssh/id_rsa
拷贝密钥文件到目标服务器
[root@WebServer3 ~]#scp ~/.ssh/id_rsa.pub 192.168.0.23:/root/.ssh/authorized_keys
注:需要判断authorized_keys是否存在已经被授权的机器,别把之前的覆盖掉