„authorize-server.sh“ hinzufügen

This commit is contained in:
Yann Mölle 2023-04-19 19:34:12 +02:00
parent 57fb7750d9
commit 4b7b1e9213

20
authorize-server.sh Normal file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# Read the server list from the specified file
SERVER_LIST_FILE="servers.conf"
SERVER_LIST=()
while IFS= read -r SERVER || [[ -n "$SERVER" ]]; do
SERVER_LIST+=("$SERVER")
done < "$SERVER_LIST_FILE"
# Read the public SSH key from the update server
UPDATE_SERVER="192.168.1.100" # replace with your update server IP address
PUBLIC_KEY=$(ssh username@${UPDATE_SERVER} "cat ~/.ssh/id_rsa.pub")
# 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
ssh username@${SERVER} "mkdir -p ~/.ssh && echo '${PUBLIC_KEY}' >> ~/.ssh/authorized_keys"
echo "Public key added to authorized_keys on server ${SERVER}"
done