Linux配置互信

luffy-0824 / 2023-08-15 / 原文

例如有以下两台机需要做互信
192.168.128.128
192.168.128.129

1、在服务器192.168.128.128生成公钥私钥对

[root@node01 .ssh]# 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:
SHA256:szQ+/rL/qBr3MlgXc7sUHUV9cjIq7WJTvRmbkkPawos root@node01
The key's randomart image is:
+---[RSA 2048]----+
| o+|
| = +|
| . + *.|
| + B + |
| S. @ + * |
| o.+O O = |
| .o=+ * + |
| .+Eo... |
| ..+O=.. |
+----[SHA256]-----+

一路默认回车,系统在/root/.ssh下生成id_rsa、id_rsa.pub

2、把id_rsa.pub公钥发送到服务端192.168.128.129机器上

[root@node01 .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.128.129

需要输入192.168.128.129的密码

3、验证

[root@node01 .ssh]# ssh root@192.168.128.129
Last login: Tue Aug 15 13:02:15 2023 from node01
[root@node02 ~]#

这时192.168.128.128可以免密登录192.168.128.129服务器