From 5e8607dbb17b7f459ec69baf1c3726951fd9f29c Mon Sep 17 00:00:00 2001 From: grimm <1769111741@qq.com> Date: Fri, 19 Jul 2024 11:14:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E5=85=AC=E9=92=A5=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ssh-copy-id.sh | 25 +++++-------------------- txt/sship.txt | 7 +++++++ 2 files changed, 12 insertions(+), 20 deletions(-) create mode 100644 txt/sship.txt diff --git a/ssh-copy-id.sh b/ssh-copy-id.sh index 35c5661..cc49ed5 100644 --- a/ssh-copy-id.sh +++ b/ssh-copy-id.sh @@ -1,22 +1,7 @@ #!/bin/bash -# 新的服务器列表,字典形式 -declare -A servers=( - ["server1"]="39.100.87.238" - ["server2"]="39.100.84.78" - ["server3"]="47.92.213.251" - ["server4"]="39.100.86.136" -) - -# 本地SSH公钥路径 -local_public_key="$HOME/.ssh/id_rsa.pub" - -# 远程主机用户名 -remote_user="root" - -# 循环遍历服务器 -for key in "${!servers[@]}"; do - server="${servers[$key]}" - # 使用sshpass将密码传递给ssh-copy-id,并将公钥追加到服务器 - sshpass -p "Royroiy123" ssh-copy-id -i "$local_public_key" "$remote_user@$server" <<< "yes" -done \ No newline at end of file +#!/bin/bash +while IFS='@' read -r ip username password; do + ssh-keyscan -H $ip >> ~/.ssh/known_hosts + sshpass -p "$password" ssh-copy-id "$username@$ip" +done < txt/sship.txt \ No newline at end of file diff --git a/txt/sship.txt b/txt/sship.txt new file mode 100644 index 0000000..4068260 --- /dev/null +++ b/txt/sship.txt @@ -0,0 +1,7 @@ +39.101.136.118@root@Royroiy123 +39.101.165.239@root@Royroiy123 +39.99.149.238@root@Royroiy123 +39.99.224.166@root@Royroiy123 +39.98.116.16@root@Royroiy123 +39.99.229.229@root@Royroiy123 +39.99.246.48@root@Royroiy123 \ No newline at end of file