From f1f4831cef3ec4f24bf45351b7800d9bb6c44787 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 29 Jun 2024 08:50:29 +0000 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=85=8D=E7=BD=AE=E5=AF=86?= =?UTF-8?q?=E9=92=A5=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- finetune/setup.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 finetune/setup.sh 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