Skip to content

Instantly share code, notes, and snippets.

@imperialwicket
Created November 6, 2012 23:25
Show Gist options
  • Save imperialwicket/4028436 to your computer and use it in GitHub Desktop.
Save imperialwicket/4028436 to your computer and use it in GitHub Desktop.
Adds a user with key and home dir
#!/bin/bash
EXPECTED=1
if [ $# -ne $EXPECTED ]
then
echo "Please provide a username argument."
exit 5
fi
USER=$1
useradd $USER -m
mkdir /home/$USER/.ssh
# hard coded key or upload a file
#echo "< the pub key >" >> /home/$USER/.ssh/authorized_keys
cat /root/pub_key.tmp >> /home/$USER/.ssh/authorized_keys
chown -R $USER:$USER /home/$USER/.ssh
chmod 700 /home/$USER/.ssh
chmod 600 /home/$USER/.ssh/*
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment