自动配置密钥对
This commit is contained in:
25
finetune/setup.sh
Normal file
25
finetune/setup.sh
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 定义主机列表
|
||||
hosts=("10.200.1.10" "10.200.1.11" "10.200.1.12")
|
||||
|
||||
# 当前主机的用户名
|
||||
user="root"
|
||||
|
||||
# 检查ssh-keygen是否已经生成密钥对
|
||||
if [ ! -f ~/.ssh/id_rsa ]; then
|
||||
echo "生成SSH密钥对..."
|
||||
ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa
|
||||
else
|
||||
echo "SSH密钥对已经存在..."
|
||||
fi
|
||||
|
||||
# 分发公钥到其他主机
|
||||
for host in "${hosts[@]}"; do
|
||||
if [ "$host" != "$(hostname -I | awk '{print $1}')" ]; then
|
||||
echo "将公钥复制到$host..."
|
||||
ssh-copy-id -i ~/.ssh/id_rsa.pub "$user@$host"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "密钥认证配置完成。"
|
||||
Reference in New Issue
Block a user