update_script/ssh-copy-id.sh

22 lines
567 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/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