Skip to content

Instantly share code, notes, and snippets.

@EnigmaCurry
Last active August 29, 2015 14:23
Show Gist options
  • Save EnigmaCurry/5cdbd04f0235883e789e to your computer and use it in GitHub Desktop.
Save EnigmaCurry/5cdbd04f0235883e789e to your computer and use it in GitHub Desktop.
A better ssh-copy-id
# 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