How to Add and Remove Users on Ubuntu

By | 2024-01-15

Ubuntu, one of the most popular Linux distributions, offers robust user management tools that allow administrators to efficiently control access to the system. Whether you’re setting up a new user account or removing an old one, understanding the process is crucial for maintaining a secure and organized environment. In this guide, we’ll walk you through the steps of adding and removing users on Ubuntu.

Adding Users

Create a New User

To add a new user, open a terminal window and use the adduser command. For example:

sudo adduser newusername

Follow the prompts to set a password and provide additional information if needed.

Grant Administrative Privileges

If you want to grant administrative privileges to the new user, add them to the sudo group:

sudo usermod -aG sudo newusername

This step allows the user to execute commands with elevated privileges.

Verify the New User

Log in as the new user to ensure the account was created successfully:

su - newusername

Removing Users

Remove User Account

To remove a user account, use the userdel command. This command only removes the user but leaves their home directory intact:

sudo userdel oldusername

Remove User Account and Home Directory

If you want to delete both the user account and its home directory, use the userdel command with the -r option:

sudo userdel -r oldusername

Additional User Management Tasks

Modify User Properties

Use the usermod command to modify user properties, such as the username, home directory, or shell:

sudo usermod -l newname oldname

Lock and Unlock User Accounts

Lock a user account to prevent login

sudo passwd -l username

Unlock a user account

sudo passwd -u username

View User Information

To display detailed information about a user, use the id command:

id username

Managing user accounts on Ubuntu is a fundamental skill for system administrators. Whether you are creating new users or cleaning up old accounts, the commands and steps outlined in this guide provide a solid foundation for effective user management. By following these practices, you can ensure a secure and organized Ubuntu system tailored to your specific needs.

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.