Linux is fundamentally designed as a multi-user operating system. Whether you are managing a web server accessed by multiple developers, or sharing a home computer with your family, Ubuntu relies on a strict system of user accounts and permissions to keep data secure and ensure that no single user can accidentally (or maliciously) destroy the system.
Understanding how to create new users, modify their privileges, and remove them safely is an essential skill for any Linux administrator. While graphical tools exist, managing users via the command line is significantly faster and more reliable.
Understanding User Types in Ubuntu
Before creating accounts, it is important to understand the three distinct types of users in a Linux system:
- The Root User: This is the absolute superuser. The root account has unrestricted access to every file and command on the system. By default, Ubuntu disables direct login to the root account for security reasons.
- Sudo Users (Administrators): These are standard users who have been granted the permission to temporarily borrow root privileges by placing the word
sudobefore a command. The primary account you created when installing Ubuntu is a sudo user. - Standard Users: These users can log in, create files in their own home directory (e.g.,
/home/john/), and run basic applications, but they cannot install software or modify critical system files.
How to Add a New User
To create a new standard user account, open your terminal (Ctrl + Alt + T) and use the adduser command followed by the new username. Since you are modifying the system, you must use sudo.
sudo adduser sarah
The system will automatically:
- Create a new user named ‘sarah’.
- Create a new home directory for her at
/home/sarah/. - Prompt you to enter and confirm a new password for the account.
- Ask for some optional information (Full Name, Room Number, etc.). You can just press Enter to skip these.
How to Grant Administrative (Sudo) Privileges
If you want the new user to be able to install software and perform administrative tasks, you need to add them to the sudo group. In Ubuntu, user privileges are largely dictated by the groups they belong to.
To grant ‘sarah’ administrative rights, run:
sudo usermod -aG sudo sarah
Let’s break down this command:
usermod: The command used to modify user accounts.-aG: This stands for “append to Group.” It tells the system to add the user to a new group without removing them from their current groups.sudo: The name of the group that grants administrative privileges.sarah: The target username.
How to Delete a User Account
When someone leaves your organization or no longer needs access to the machine, you should remove their account to maintain security. You can use the deluser command for this.
If you just want to delete the user’s login access but keep their files intact, run:
sudo deluser sarah
If you want to completely wipe the user from the system and delete their home directory and all their personal files simultaneously, add the --remove-home flag:
sudo deluser --remove-home sarah
Viewing Existing Users
If you take over an existing server, you might need to see who already has an account. All user account information in Linux is stored in a plain text file located at /etc/passwd.
To view a clean list of all human users on the system (filtering out the dozens of invisible system accounts used by software services), you can run this command:
getent passwd | awk -F: '$3 >= 1000 && $1 != "nobody" {print $1}'
Conclusion
By mastering the adduser, usermod, and deluser commands, you gain complete control over who can access your Ubuntu system and what they are allowed to do. Always follow the principle of least privilege: only grant sudo access to users who absolutely need it to perform their jobs.