diff --git a/finetune/setup.sh b/finetune/setup.sh new file mode 100644 index 0000000..514d283 --- /dev/null +++ b/finetune/setup.sh @@ -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 "密钥认证配置完成。" \ No newline at end of file