Skip to content

Instantly share code, notes, and snippets.

@vaughany
Created August 16, 2018 11:00
Show Gist options
  • Save vaughany/b6fd9105e60c2296c4825f4077935de0 to your computer and use it in GitHub Desktop.
Save vaughany/b6fd9105e60c2296c4825f4077935de0 to your computer and use it in GitHub Desktop.

Adding a new user to an Ubuntu Linux machine

Do all this in Bash.

1. Create the new user

Obviously change the username laptop-admin to whatever you like:

$ sudo adduser laptop-admin

Adding user `laptop-admin' ...
Adding new group `laptop-admin' (1022) ...
Adding new user `laptop-admin' (1022) with group `laptop-admin' ...
Creating home directory `/home/laptop-admin' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:

Type in a good, strong password (this account will have admin rights, after all).

Retype new UNIX password:

...and type it again.

passwd: password updated successfully

There are some more questions, but you can ignore these if you want (just press Enter).

Changing the user information for laptop-admin
Enter the new value, or press ENTER for the default
	Full Name []:
	Room Number []:
	Work Phone []:
	Home Phone []:
	Other []:
Is the information correct? [Y/n]

Press enter to confirm it's all good.

2. Give the new user admin rights

The command to do this is much the same as the previous command (remembering to change the username laptop-admin to whatever you used above), but with sudo on the end.

$ sudo adduser laptop-admin sudo

Adding user `laptop-admin' to group `sudo' ...
Adding user laptop-admin to group sudo
Done.

3. Locking the account

Use this if, say, you had to create an account against your will but didn't want anyone logging into it...

$ sudo passwd -l laptop-admin

Note: On Ubuntu, this will show an incorrect password error message instead of an account locked error message, if the user tries to log in. I believe this is known as 'plausible deniability'.

4. Unlocking the account

$ sudo passwd -u laptop-admin

5. Deleting the user (completely)

$ sudo deluser laptop-admin --remove-home

This should also remove the group, but you can try running the following just for completeness' sake.

$ sudo delgroup laptop-admin

I get the following:

The group `laptop-admin' does not exist.

You can also $ ls /home/, which should show the user's home folder is absent.`

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