两台机器之间建立信任关系的步骤:
1. 在机器1上root用户执行ssh-keygen命令,生成建立安全信任关系的证书,直接Enter
[root@CentOS64-x64 ~]# ssh-keygen -b 1024 -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): //不需要输入内容
Created directory '/root/.ssh'.
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:
a5:bf:a6:a8:ef:39:b6:80:85:92:ca:5d:d8:3f:37:9d root@CentOS64-x64
The key's randomart image is:
+--[ RSA 1024]----+
| |
| |
| . |
| . .o o |
|o ...o S |
|o..o. . .. . |
|..... o o.E |
| .ooo o. |
| .=*o.o. |
+-----------------+
注意:在程序提示输入passphrase时直接输入回车,表示无证书密码。
上述命令将生成私钥证书id_rsa和公钥证书id_rsa.pub,存放在用户家目录的.ssh子目录中。
2. 将公钥证书id_rsa.pub复制到机器2的/root/.ssh子目录中,同时将文件名更换为authorized_keys
执行这步之前,确认当前机器存在/root/.ssh目录,不存在的话要先执行前面的步骤1
[root@Client root]# scp -p /root/.ssh/id_rsa.pub root@192.168.146.20:/root/.ssh/authorized_keys
root@192.168.146.20'spassword: //输入146.20root用户的密码
id_rsa.pub 100% 227 0.2KB/s 00:00
经过以上2步,就在机器1的root和机器2的root之间建立安全信任关系。但是只是机器1操控机器2的时候不需要输入密码,机器2往机器2操控则还是需要密码的,需要将机器2的公钥给机器1:拷贝/root/.ssh/id_rsa.pub中的内容放到机器1中的/root/.ssh/authorized_keys文件中。一行表示一条公钥