batchupdate/authorize-server

20 lines
772 B
Plaintext
Raw Normal View History

2023-04-19 19:34:12 +02:00
#!/bin/bash
# Read the server list from the specified file
SERVER_LIST_FILE="servers.conf"
2023-04-19 19:37:56 +02:00
2023-04-19 19:37:14 +02:00
while IFS= read -r SERVER || [ -n "$SERVER" ]; do
2023-04-19 19:34:12 +02:00
SERVER_LIST+=("$SERVER")
done < "$SERVER_LIST_FILE"
# Read the public SSH key from the update server
2023-04-19 19:48:56 +02:00
UPDATE_SERVER="10.0.3.77" # replace with your update server IP address
2023-04-19 19:44:50 +02:00
PUBLIC_KEY=$(ssh root@${UPDATE_SERVER} "cat ~/.ssh/id_rsa.pub")
2023-04-19 19:34:12 +02:00
# Loop through the server list and add the public key to the authorized_keys file of each server
for SERVER in "${SERVER_LIST[@]}"
do
# Establish SSH connection to remote server and add the public key to the authorized_keys file
2023-04-19 19:44:50 +02:00
ssh root@${SERVER} "mkdir -p ~/.ssh && echo '${PUBLIC_KEY}' >> ~/.ssh/authorized_keys"
2023-04-19 19:34:12 +02:00
echo "Public key added to authorized_keys on server ${SERVER}"
done