Creating user accounts on Linux can be easy. If you run Linux as a Desktop there are likely a few GUI tools to add and modify User Accounts. Unfortunately, since most Linux Servers run without GUIs, you must know the commands and how to use them to create and remove users.

This guide will present two options for user account creation and two options for removing user accounts.

The things you will need before starting:

  • Access to a Linux Desktop or Server.
  • Access to the root account or an account with sudo access.

Creating User Accounts

Option 1: adduser

This is the simplest command to add a user. This command prompts you to set a user password.

$ sudo adduser newuser
Adding user `newuser' ...
Adding new group `newuser' (1002) ...
Adding new user `newuser' (1002) with group `newuser' ...
Creating home directory `/home/newuser' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: [Enter a password here]
Retype new UNIX password: [Enter a password here]
passwd: password updated successfully
Changing the user information for newuser
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] y


Option 2: useradd

This command creates the user account, but it is a 2 part process to create a user account and set a password.

$ sudo useradd -m newuser (m tells the command to make the home directory if it does not already exist)
$ sudo passwd newuser (after creating the user account)
Enter new UNIX password: [Enter a password here]
Retype new UNIX password: [Enter a password here]
passwd: password updated successfully

The following comand displays the default settings that are used for user account creation.

$ sudo useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=no

Removing User Accounts

Option 1: deluser

This command removes the user account and removes the home directory. This command has far more available options than the next command such as backing up the home directory before deleting the directory.

$ sudo deluser -remove-home newuser
Looking for files to backup/remove ...
Removing files ...
Removing user `newuser' ...
Warning: group `newuser' has no more members.
Done.

Option 2: userdel

This command is an extremely barebones command. This command doesn't provide any more options than r and f.

$ sudo userdel -rf newuser (the -r removed the home directory and the f forces removal of all files in the home directory)

If you forget to enter the options, you'll need remove the home folder afterward.

$ sudo rm /home/newuser

 

While there are plenty of additional settings which can be made to some of these commands, this is a good primer for future user modifications such as adding groups and changing home folders.