配置主机之间的信任关系



下面是用root用户执行配置的,也可以切换到其他用户去做这个配置,那么跳转的时候就 ssh [email protected]即可


1.生成各个主机自己的秘钥文件
主机a和主机b相同操作
[root@sfxbdb04 ~]# cd .ssh
[root@sfxbdb04 .ssh]# ls -lrt
total 12
-rw-r--r-- 1 root root  857 Sep 13 14:26 authorized_keys
-rw-r--r-- 1 root root 4725 Oct 29 16:29 known_hosts

[root@sfxbdb04 .ssh]# rm -f authorized_keys
[root@sfxbdb04 .ssh]# rm -f known_hosts
[root@sfxbdb04 .ssh]# ssh-keygen -t dsa     ---有的是用rsa,一路回车即可
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
34:8a:16:02:25:dc:20:ae:ee:95:b1:32:99:e7:3b:6c [email protected]

[root@sfxbdb04 .ssh]# ls -lrt
total 8
-rw-r--r-- 1 root root 618 Oct 30 16:55 id_dsa.pub
-rw------- 1 root root 668 Oct 30 16:55 id_dsa
[root@sfxbdb04 .ssh]# cat id_dsa.pub >>authorized_keys

2.把主机a的authorized_keys传到另一台主机b相同目录
scp authorized_keys [email protected]:/root/.ssh

3.主机b将自身的秘钥写入authorized_keys
[root@sfxbdb04 .ssh]# ls -l
total 12
-rw-r--r-- 1 root root 1854 Oct 30 16:59 authorized_keys
-rw------- 1 root root  668 Oct 30 16:55 id_dsa
-rw-r--r-- 1 root root  618 Oct 30 16:55 id_dsa.pub

cat id_dsa.pub >>authorized_keys

4.查看
cat -n authorized_keys

5.再把这个传回去给主机a就可以了。
scp authorized_keys [email protected]:/root/.ssh

6.跳转测试(2台主机都能成功执行下面2个即成功)
ssh 192.168.1.13
ssh 192.168.1.14

记得第一次需要yes一下

猜你喜欢

转载自906179271.iteye.com/blog/2263194