How to Add and Delete Users in Linux
This post covers the essential Linux+ skill of managing user accounts using the useradd and userdel commands. It walks through creating users with common options, setting passwords, and safely removing accounts with practical terminal examples.
Managing user accounts is one of the most fundamental responsibilities of a Linux system administrator. Whether you are setting up a new server, onboarding a team member, or cleaning up old accounts, knowing how to add and delete users in Linux is a skill you will use constantly. This post walks you through the core commands you need to get started.
Why User Management Matters
Linux is a multi-user operating system. Every person or service that interacts with the system should have its own account. This keeps things organized, allows for proper permission control, and makes auditing easier. Sharing accounts is a security risk and a bad habit to break early.
Adding a User with useradd
The useradd command is the standard tool for creating new user accounts on Linux. At its simplest, you provide a username and the system handles the rest.
sudo useradd jsmithThis creates a new user named jsmith. However, the account will not have a password yet, which means the user cannot log in. Set a password immediately after creating the account:
sudo passwd jsmithYou will be prompted to enter and confirm a new password for that user.
Useful useradd Options
The useradd command has several flags that make account creation more useful in practice:
- -m: Create a home directory for the user at
/home/username - -s: Specify the user's login shell (for example,
/bin/bash) - -c: Add a comment or full name to the account
- -G: Add the user to one or more supplementary groups
Here is a more complete example that creates a user with a home directory, a specific shell, and a full name:
sudo useradd -m -s /bin/bash -c "Jane Smith" jsmithAfter running this, you can verify the account was created by checking the /etc/passwd file:
grep jsmith /etc/passwdThe output will look something like this:
jsmith:x:1001:1001:Jane Smith:/home/jsmith:/bin/bashEach field is separated by a colon and tells you the username, password placeholder, user ID, group ID, comment, home directory, and shell.
Deleting a User with userdel
When an account is no longer needed, you use the userdel command. The basic syntax removes the account but leaves the home directory intact:
sudo userdel jsmithIf you want to remove the user's home directory and mail spool at the same time, add the -r flag:
sudo userdel -r jsmithBe careful with the -r flag. Once the home directory is deleted, any files stored there are gone unless you have a backup. In production environments, it is often a good idea to archive a user's home directory before deleting it.
Checking Before You Delete
Before deleting an account, it is worth confirming the user exists and checking whether they are logged in:
id jsmith
who | grep jsmithIf the user is currently logged in, you should log them out or wait for an appropriate time before removing the account.
A Note on useradd vs adduser
On Debian-based systems like Ubuntu, you may also encounter the adduser command. This is a higher-level script that provides an interactive, more user-friendly experience compared to useradd. The useradd command is lower-level and available on virtually every Linux distribution, which is why it is the focus for the Linux+ exam.
What's Next
Now that you know how to create and remove user accounts, the next step is understanding how to modify existing accounts. The usermod command lets you change a user's shell, groups, home directory, and more without deleting and recreating the account. We will cover that in the next post in this series.
If you want to go deeper on Linux user management concepts, the CompTIA Linux+ Study Guide by Richard Blum is an excellent companion resource for everything covered in this series.
Tools and resources for this topic
- CompTIA Linux+ Study Guide โ Comprehensive Linux+ exam preparation covering system administration, security, and scripting.