Managing user accounts is one of the most basic system administration tasks on any Linux server. On Ubuntu 18.04, you can add, modify, and remove users directly from the command line using simple built-in tools.
This guide shows you how to add and delete users on Ubuntu 18.04 and how to grant a new user sudo privileges.
Prerequisite: You need root or sudo access to manage user accounts.
The adduser command creates a new user account and sets up their home directory automatically.
To add a new user named john:
bashsudo adduser john
The command walks you through a short setup process. It will ask you to set and confirm a password, then optionally fill in some basic profile details like full name and phone number. Press Enter to skip any field you do not want to fill in.
The new user’s home directory is created at /home/john, and a set of default configuration files is copied into it automatically.
By default, new users do not have administrative access. To give a user sudo privileges, add them to the sudo group:
bashsudo usermod -aG sudo john
To confirm the change worked, switch to the new user and run a command with sudo:
bashsu - johnsudo whoami
Output: root
If you see root, the user has sudo access.
To remove a user account without deleting their home directory and files:
bashsudo deluser john
If you want to remove the user and delete their home directory and all their files at the same time:
bashsudo deluser --remove-home john
Use the --remove-home flag carefully. Once deleted, those files cannot be recovered unless you have a backup.
To see a list of all user accounts on the system, print the /etc/passwd file:
bashcut -d: -f1 /etc/passwd
This shows every account, including system accounts. Regular user accounts typically start from UID 1000 and above.
User management on Ubuntu is straightforward once you know the right commands. Use adduser to create, usermod to modify, and deluser to remove accounts. Got questions? Leave a comment below.
Setting a static IP address on your server is a smart move. It ensures your…
Xrdp is an open-source implementation of the Microsoft Remote Desktop Protocol (RDP). It lets you access…
Wine (short for "Wine Is Not an Emulator") is a compatibility layer that lets you run…
KVM (Kernel-based Virtual Machine) is an open-source virtualization technology built into the Linux kernel. It lets…
Ubuntu 20.04 LTS (code name Focal Fossa) was released on April 23, 2020. It is a…
Google Chrome is the most widely used web browser in the world. It is fast, secure,…