ssh两台主机建立信任关系
A主机(10.104.11.107) B主机(10.104.11.128)
A: ssh-keygen -t rsa
[root@H0f .ssh]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /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: c3:41:52:b3:6c:0e:ca:37:87:c6:18:7c:80:6e:fb:1e root@H0f The key's randomart image is: +--[ RSA 2048]----+ | .. ..+ | | .. . + o | | . o o = | | o. * * . | | . .+ * S | | . o o . | | .E | | .. | | .. | +-----------------+
[root@H0f .ssh]# ll
total 12
-rw-------. 1 root root 1743 Mar 26 03:06 id_rsa #密钥
-rw-r--r--. 1 root root 390 Mar 26 03:06 id_rsa.pub #公钥
-rw-r--r--. 1 root root 395 Mar 26 03:08 known_hosts
[root@H0f .ssh]# scp -r id_rsa.pub 10.104.11.107:/root/.ssh/authorized_keys root@10.104.11.107's password: #输入主机B的登录密码 id_rsa.pub
B:ssh-keygen -t rsa
[root@H0f .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /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:
c3:41:52:b3:6c:0e:ca:37:87:c6:18:7c:80:6e:fb:1e root@H0f
The key's randomart image is:
+--[ RSA 2048]----+
| .. ..+ |
| .. . + o |
| . o o = |
| o. * * . |
| . .+ * S |
| . o o . |
| .E |
| .. |
| .. |
+-----------------+
[root@H0f .ssh]# ll
total 16
-rw-r--r-- 1 root root 390 Mar 26 04:00 authorized_keys
-rw------- 1 root root 1743 Mar 26 04:02 id_rsa
-rw-r--r-- 1 root root 390 Mar 26 04:02 id_rsa.pub
-rw-r--r-- 1 root root 395 Mar 26 03:10 known_hosts
[root@H0f .ssh]# scp -r id_rsa.pub 10.104.11.128:/root/.ssh/authorized_keys
root@10.104.11.128's password:
id_rsa.pub
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /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:
c3:41:52:b3:6c:0e:ca:37:87:c6:18:7c:80:6e:fb:1e root@H0f
The key's randomart image is:
+--[ RSA 2048]----+
| .. ..+ |
| .. . + o |
| . o o = |
| o. * * . |
| . .+ * S |
| . o o . |
| .E |
| .. |
| .. |
+-----------------+
[root@H0f .ssh]# ll
total 16
-rw-r--r-- 1 root root 390 Mar 26 04:00 authorized_keys
-rw------- 1 root root 1743 Mar 26 04:02 id_rsa
-rw-r--r-- 1 root root 390 Mar 26 04:02 id_rsa.pub
-rw-r--r-- 1 root root 395 Mar 26 03:10 known_hosts
[root@H0f .ssh]# scp -r id_rsa.pub 10.104.11.128:/root/.ssh/authorized_keys
root@10.104.11.128's password:
id_rsa.pub
[root@H0f .ssh]# ssh 10.104.11.128 #建立连接
Enter passphrase for key '/root/.ssh/id_rsa':
Last login: Mon Mar 26 02:56:59 2018 from 10.104.10.85
[root@H0f ~]# ls
1_shell.sh 3_shuzu.sh anaconda-ks.cfg Documents if.sh Music Templates Videos
2_shell.sh a_array.sh danted_install.sh Downloads install.log Pictures testa
2.txt aha_array.sh Desktop if_file.sh install.log.syslog Public test.txt
Enter passphrase for key '/root/.ssh/id_rsa':
Last login: Mon Mar 26 02:56:59 2018 from 10.104.10.85
[root@H0f ~]# ls
1_shell.sh 3_shuzu.sh anaconda-ks.cfg Documents if.sh Music Templates Videos
2_shell.sh a_array.sh danted_install.sh Downloads install.log Pictures testa
2.txt aha_array.sh Desktop if_file.sh install.log.syslog Public test.txt
![](https://images2018.cnblogs.com/blog/787128/201803/787128-20180326201319633-783764708.png)