Skip to content

Instantly share code, notes, and snippets.

@alexmerser
Forked from awd-git/add-newuser.sh
Last active June 28, 2016 04:20
Show Gist options
  • Save alexmerser/4750289b86217ada72da to your computer and use it in GitHub Desktop.
Save alexmerser/4750289b86217ada72da to your computer and use it in GitHub Desktop.
HowTo add user on ubuntu with sudo and ssh key access
if [ "$1" == '' ]; then
echo "Please add a username to the command"
exit 1;
fi
newuser=$1
# 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
@dabest1
Copy link

dabest1 commented Jun 28, 2016

With this command:
sudo chown -R $newuser:$newuser
Did you mean to do:
sudo chown -R $newuser:$newuser /home/$newuser/.ssh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment