现需设置 主机A 免密码登陆 主机B
主机A: 192.168.0.61
主机B: 192.168.0.62
1、在主机A中生成公钥和私钥
cd /~/.ssh
ssh-keygen -t rsa
主机A的提示如下,在要求输入密码(Enter passphrase)的提示中按回车即为空密码
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/Allen/.ssh/id_rsa): /Users/Allen/.ssh/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/Allen/.ssh/id_rsa.
Your public key has been saved in /Users/Allen/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:luC3egH9J9VEDYxToA8VS6oPlXT8jiViukOvmc/n2+I Allen@localhost
The key's randomart image is:
+---[RSA 2048]----+
| ..*B+o |
| . B+.o .|
| .. * .= |
| ....+ooo + |
| ..S+ o.= |
| o++o o . |
| ..+.o |
| .++. o. |
| ..++o+Eo. |
+----[SHA256]-----+
2、把主机A生成的公钥id_rsa.pub复制至主机B
scp id_rsa.pub root@192.168.0.62:/root/.ssh/id_rsa.pub
3、在主机B上把主机A的公钥复制至authorized_keys
cat id_rsa.pub >>/root/.ssh/authorized_keys
完成上述步骤后,下次在主机A(192.168.0.61)上使用ssh root@192.168.0.62 登陆主机B(192.168.0.62)将不需要密码