Created
May 10, 2011 05:05
-
-
Save timoxley/963921 to your computer and use it in GitHub Desktop.
Scalr Script: Append pubkey to authorized keys file for a provided user.
This file contains 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
#!/bin/bash | |
USER="%user%" | |
KEY="%key%" | |
FILE="%file%" | |
if [[ ! -n "$KEY" ]]; then | |
KEY="INSERT YOUR DEFAULT PUBLIC KEY HERE" | |
fi | |
if [[ ! -n "$FILE" ]]; then | |
if [[ ! -d /home/$USER/".ssh" ]]; then | |
echo 'Creating .ssh folder for user...' | |
mkdir /home/$USER/.ssh && echo "Folder created." || { echo "Failed!" ; exit 1 ; } | |
fi | |
printf "Appending key to authorized_keys file for %s ..." "$USER" | |
echo $USER | |
echo $KEY >> /home/$USER/.ssh/authorized_keys | |
exit 0; | |
else | |
printf 'Appending key to authorized_keys file to %s ' "$FILE" | |
echo "$KEY" >> "$FILE" && echo "Success!" || { echo "Failed!" ; exit 1 ; } | |
exit 0; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment