Skip to content

Instantly share code, notes, and snippets.

@kalebo
Last active September 4, 2020 14:36
Show Gist options
  • Save kalebo/e727e2bb454bbf15bfc04903a0ced4f6 to your computer and use it in GitHub Desktop.
Save kalebo/e727e2bb454bbf15bfc04903a0ced4f6 to your computer and use it in GitHub Desktop.
Automates the first few steps of creating a user and poplating it with an allowed ssh key from gitlab
NEWUSER=$1
USERFULLNAME=$2
PASS=$(diceware)
adduser --disabled-password --gecos "$USERFULLNAME,,," $NEWUSER
echo "$NEWUSER:$PASS" | chpasswd
sudo -u $NEWUSER -s <<USERSCRIPT
mkdir -p ~/.ssh
umask 177
curl -o ~/.ssh/authorized_keys https://gitlab.coreform.com/$NEWUSER.keys
echo $PASS > ~/temp.password
USERSCRIPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment