-
-
Save alexmerser/4750289b86217ada72da to your computer and use it in GitHub Desktop.
HowTo add user on ubuntu with sudo and ssh key access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With this command:
sudo chown -R $newuser:$newuser
Did you mean to do:
sudo chown -R $newuser:$newuser /home/$newuser/.ssh