Skip to content

Instantly share code, notes, and snippets.

@timoxley
Created May 10, 2011 05:05
Show Gist options
  • Save timoxley/963921 to your computer and use it in GitHub Desktop.
Save timoxley/963921 to your computer and use it in GitHub Desktop.
Scalr Script: Append pubkey to authorized keys file for a provided user.
#!/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