What you will read?
Managing users on Ubuntu is a core task for system administrators, developers, and VPS owners. Whether you’re setting up a secure environment for your team or cleaning up unused accounts, knowing how to add and delete users properly ensures better control, security, and performance.
The adduser command is the most user-friendly way to create a new account on Ubuntu. It automatically sets up the home directory, shell, and prompts for a password and user details.
sudo adduser newusername
The useradd command is more flexible and script-friendly but requires additional flags to configure the user properly. It’s commonly used in automated deployments or VPS provisioning.
sudo useradd -m -s /bin/bash newusername sudo passwd newusername
To allow a user to run administrative commands (like installing packages or restarting services), you need to add them to the sudo group.
sudo usermod -aG sudo newusername
deluserWhen a user no longer needs access, you can remove their account while keeping their files intact. This is useful for auditing or transferring data later.
sudo deluser oldusername
When a user account is no longer needed and you want to fully clean up their data, you can delete both the account and its associated home directory to free up space and maintain system hygiene.
sudo deluser --remove-home oldusername
The userdel command is a lower-level alternative to deluser, often used in scripts or minimal environments.
sudo userdel oldusername
To remove the user’s home directory as well:
sudo userdel -r oldusername
To audit user accounts or verify access on your Ubuntu server, you can list all registered users by reading system files or using built-in commands.
cut -d: -f1 /etc/passwd
Sure! Here’s a short, SEO-friendly intro for that command:
getent passwd | cut -d: -f1
To see which groups a user belongs to — including whether they have sudo access — use the groups command.
groups newusername