Home

Adding and removing users on Ubuntu and Debian

One of the first things you do on a fresh Ubuntu or Debian box is set up the users — give people the right level of access, lock down the rest. This post is a quick reference for the commands I actually use.

You'll need root or sudo privileges to add or remove users.

Adding a user

Ubuntu and Debian ship two CLIs for this: useradd and adduser. useradd is the low-level binary; adduser is a friendlier Perl wrapper around it that prompts for the password and the optional fields.

In practice, just use adduser:

bash
sudo adduser samet

Output:

bash
Adding user `samet' ...Adding new group `samet' (1001) ...Adding new user `samet' (1001) with group `samet' ...Creating home directory `/home/samet' ...

It'll then prompt for a password and a few optional fields (full name, room number, etc.) — the password is the only thing you really need to set; everything else can be blank.

If the new user needs sudo:

bash
sudo usermod -aG sudo samet

Log out and back in for the group change to take effect.

Removing a user

Two options for removing: userdel (low-level) or deluser (the friendly wrapper). I cover userdel in more detail in its own post.

For Debian/Ubuntu, deluser is the easiest:

bash
sudo deluser samet

This removes the account but leaves the home directory in /home/samet alone. To also wipe the home directory:

bash
sudo deluser --remove-home samet

Be careful with --remove-home — once it's gone, it's gone. If there's any chance you'll need their files later, take a backup first or remove the account and the home directory in two separate steps.