Last active
February 16, 2025 09:30
-
-
Save elico/8d6f48475dc5640e4dc9904aca281176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
IP_LIST_FILE="ips" | |
KEYS_FILE="keys.txt" | |
SSH_PASS="$(head -1 ssh_password)" | |
SSH_USER="root" | |
SSH_PORT="22" | |
mapfile -t keys < "${KEYS_FILE}" | |
mapfile -t ips < "${IP_LIST_FILE}" | |
for key in "${keys[@]}"; do | |
SSH_KEY_TMP_FILE="$(mktemp)" | |
chmod 600 "${SSH_KEY_TMP_FILE}" | |
echo "${key}" > "${SSH_KEY_TMP_FILE}" | |
for ip in "${ips[@]}"; do | |
sshpass -p "${SSH_PASS}" ssh-copy-id -i "${SSH_KEY_TMP_FILE}" \ | |
"${SSH_USER}@${ip}" -p "${SSH_PORT}" | |
done | |
rm -vf "${SSH_KEY_TMP_FILE}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment