SSH建立信任关系

A机器不用密码直接ssh登陆B机器:

1、生成A机器的公私钥匙对,用这条命令生成:ssh-keygen -b 1024 -t rsa

[root@localhost ~]# ssh-keygen -b 1024 -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:
40:44:8d:2c:20:bd:c0:1b:b2:01:9f:e8:f9:bb:db:67 root@localhost.localdomain

可以看到公钥和私钥都生成在了.shh目录下,公钥为id_rsa.pub,私钥为id_rsa

2、拷贝A机器的公钥到B机器的.shh目录(没有.ssh目录的话,手动建立),加入到authorized_keys文件中

用这个命令:scp .ssh/id_rsa.pub root@B机器IP:~/.ssh/
完成拷贝

3、登录B机器,追加A机器的公钥到B机器的认证文件中:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

搞定!