Last active
August 29, 2015 14:23
-
-
Save EnigmaCurry/5cdbd04f0235883e789e to your computer and use it in GitHub Desktop.
A better ssh-copy-id
This file contains hidden or 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
# Copy an SSH key to multiple accounts on multiple machines. | |
# Better than ssh-copy-id because it works with systems that don't | |
# use passwords over ssh. | |
echo "Enter the ssh pub key: " | |
read PUBKEY | |
echo "Enter the hosts to copy the key to (separated by space)" | |
read HOSTS | |
HOSTS=(${HOSTS// / }) | |
echo "Enter the usernames to add the key to (separated by space)" | |
read USERS | |
USERS=(${USERS// / }) | |
echo "-------" | |
echo -n "Pubkey to copy: " | |
echo $PUBKEY | |
echo "Hosts:" | |
for i in "${HOSTS[@]}"; do | |
echo -n " " | |
echo $i | |
done | |
echo "Users:" | |
for i in "${USERS[@]}"; do | |
echo -n " " | |
echo $i | |
done | |
echo "---" | |
echo "Copy the key to the users on these hosts? (y/N)" | |
read continue | |
case $continue in | |
[Yy]* ) ;; | |
[Nn]* ) echo "OK, nevermind"; exit;; | |
* ) echo "OK, nevermind."; exit;; | |
esac | |
for host in "${HOSTS[@]}"; do | |
for user in "${USERS[@]}"; do | |
ssh -l $user $host "echo $PUBKEY >> ~/.ssh/authorized_keys" | |
echo "$user@$host: DONE" | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment