Skip to content

Instantly share code, notes, and snippets.

@aliva
Created April 13, 2019 10:30
Show Gist options
  • Save aliva/3c452c30d45e29389db53edb6909c199 to your computer and use it in GitHub Desktop.
Save aliva/3c452c30d45e29389db53edb6909c199 to your computer and use it in GitHub Desktop.
add ssh key to authorized_keys in all servers (give access to all server for a new key)
#!/bin/bash
# create a file named key which contains the public key for new user
export SERVERS="ip1 ip2 ip3"
for server in $SERVERS
do
echo "============="
echo $server
ssh $server "hostname"
cat key | ssh ${server} "tee -a ~/.ssh/authorized_keys"
done
@vahit
Copy link

vahit commented Apr 13, 2019

Use as ssh-copy-id -i /paht/to/key/file ${server}

@aliva
Copy link
Author

aliva commented Apr 13, 2019

@vahit I already have access to server with my ssh key, This scripts simply connects to those servers and gives access to second person

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment