„setup-servers“ hinzufügen
This commit is contained in:
parent
5b67b1351f
commit
f0c8f02318
27
setup-servers
Normal file
27
setup-servers
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Read the server list from a file
|
||||||
|
servers_file="servers.txt"
|
||||||
|
if [ ! -f "$servers_file" ]; then
|
||||||
|
echo "Error: $servers_file does not exist."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
servers=($(cat "$servers_file"))
|
||||||
|
|
||||||
|
# Path to the SSH key file
|
||||||
|
ssh_key_file="/root/.ssh/id_rsa.pub"
|
||||||
|
|
||||||
|
# Loop through servers and add the SSH key to the authorized_keys file
|
||||||
|
for server in "${servers[@]}"
|
||||||
|
do
|
||||||
|
echo "Adding SSH key to $server"
|
||||||
|
ssh -o StrictHostKeyChecking=no $server "sudo mkdir -p /root/.ssh && sudo chmod 700 /root/.ssh"
|
||||||
|
cat $ssh_key_file | ssh -o StrictHostKeyChecking=no $server "sudo tee -a /root/.ssh/authorized_keys > /dev/null"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "SSH key added to $server"
|
||||||
|
else
|
||||||
|
echo "Failed to add SSH key to $server"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "SSH keys added to all servers"
|
Loading…
Reference in New Issue
Block a user