新增SSH免密设置

vi ~/.ssh/config

--在末尾新增新的主机SSH配置

Host host3
  HostName 45.93.28.212
  Port 22
  User root
  IdentityFile ~/.ssh/id_rsa_host3

具体步骤:

1\先手动确认主机指纹

root@jgui:~# ssh -p 22 root@45.93.28.212
The authenticity of host '45.93.28.212 (45.93.28.212)' can't be established.
ECDSA key fingerprint is SHA256:Adg/lz4CWoorF8vDZ/+/r4kLnjr1qz6KcJXPRVIZURA.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '45.93.28.212' (ECDSA) to the list of known hosts.
root@45.93.28.212's password:
========================
This image built by WIKIHOST OpenSource.
Build time: 2023-10-08 18:06:41 UTC.
[root@VM2668899690111DA ~]# exit

2. 生成新的密钥对(为主机C)bash

ssh-keygen -t rsa -f ~/.ssh/id_rsa_c

按提示完成。


3. 将新公钥复制到主机C

假设主机C的 IP 是 X.X.X.X,端口是 YYYY,用户名是 root,执行:

 
ssh-copy-id -i ~/.ssh/id_rsa_c.pub -p YYYY root@X.X.X.X

(如果第一次连接,可能需要输入密码)

4. 测试免密登录

systemctl restart sshd

ssh host_c
posted @ 2025-07-30 14:46  一只竹节虫  阅读(7)  评论(0)    收藏  举报