三台ubuntu22相互免密登录最快

环境

  • 主机1: node1 (IP: 192.168.1.10)

  • 主机2: node2 (IP: 192.168.1.11)

  • 主机3: node3 (IP: 192.168.1.12) 

步骤 1: 配置主机名解析(在所有节点上)

编辑 /etc/hosts 文件:

bash
sudo nano /etc/hosts

添加以下内容:

192.168.1.10 node1
192.168.1.11 node2
192.168.1.12 node3

· 验证解析:

bash
ping -c 3 node1
ping -c 3 node2
ping -c 3 node3

步骤 2: 生成 SSH 密钥对(在所有节点上)

bash
# 生成 RSA 密钥(一路回车即可)
ssh-keygen -t rsa -b 4096

# 或者生成 ED25519 密钥(更安全)
ssh-keygen -t ed25519

密钥将保存在:~/.ssh/id_rsa(私钥)和 ~/.ssh/id_rsa.pub(公钥)

步骤 3: 创建授权密钥文件

在 node1 上执行:

bash
ssh-copy-id node1
ssh-copy-id node2
ssh-copy-id node3

在 node2 上执行:

bash
ssh-copy-id node1
ssh-copy-id node2  
ssh-copy-id node3

在 node3 上执行:

bash
ssh-copy-id node1
ssh-copy-id node2
ssh-copy-id node3

步骤 4: 设置正确的权限

在所有节点上执行:

bash
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
chmod 644 ~/.ssh/known_hosts

步骤 5: 测试免密登录

ssh node1
ssh node2
ssh node3

以上在本地测试完成,但助于ds完成攻略。
 
posted @ 2025-09-17 16:53  zhg1016  阅读(35)  评论(0)    收藏  举报