Skip to content

Instantly share code, notes, and snippets.

@awd-git
Last active September 8, 2015 11:54
Show Gist options
  • Save awd-git/3be21c170cda416c1381 to your computer and use it in GitHub Desktop.
Save awd-git/3be21c170cda416c1381 to your computer and use it in GitHub Desktop.
HowTo add user on ubuntu with sudo and ssh key access
# Add user to a ubuntu system with sudo rights
if [ "$1" == '' ]; then
echo "Please add a username to the command"
exit 1;
fi
newuser=$1
# NOTE: adduser has option --ingropup and --add_extra_group
# but they cannot be used to add user at the same time to a
# grouup.
# Step1) first create user account
sudo adduser $newuser
# this will ask to set a new password and some other basic account information
# Step2) add user to group sudo
sudo adduser $newuser sudo
# for ssh key access add .ssh folder and authorized_keys file
sudo mkdir /home/$newuser/.ssh
sudo touch /home/$newuser/.ssh/authorized_keys
# Note: you will also have to add the public key to the file
sudo chown -R $newuser:$newuser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment