Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.
Learn how to add and remove users in Linux, including user creation, deletion, and best practices for effective user administration, system security, and access control.
Linux is a multi-user operating system, which means that multiple users can use it simultaneously. Linux has a beautiful mechanism for managing users in a system. One of the most significant duties of a system administrator is to manage the system’s users and groups.
In this article, I’ll show you how to add and remove user accounts from the command line in Linux.
Table of Contents
Add New Users in Linux
To obtain the user manual, execute the command below.
In Linux, creating the user “cloudbooklet” involves assigning a unique user ID, updating the /etc/passwd file with user details, and automatically generating a home directory at /home/cloudbooklet for storing user-specific files and configurations.
The next step after creating a user is to assign a password to that user. Set a password for the newly formed user and enable login access with the “passwd” command.
sudo passwd <username>
The command will prompt you for a new password and will request confirmation:
[ cloudbooklet@cloudbooklet ~ ] $ sudo passwd cloudbooklet
[ sudo] password for cloudbooklet :
Changing password for user cloudbooklet .
New password :
Retype new password :
passwd : all the authentication tokens updated successfully.
By executing the “passwd” command, the user’s password is securely stored in the /etc/shadow file in an encrypted format. Once the command is run successfully, the newly created user will gain the ability to log in using their provided credentials.
You may see the new user’s ID by running id -u username. In our example, cloudbooklet was assigned the ID 1001:
[ cloudbooklet@cloudbooklet ~ ] $ id -u cloudbooklet
Remove a User in Linux
In Linux, use the userdel command to delete a user as follows:
sudo userdel <username>
By default, this command saves the user’s home directory as well as several other special files, such as the user’s cron task list. If you also want to delete these files, use the --remove-all-files flag.
For example, if you wish to delete the user cloudbooklet as well as his home directory, run the following command:
Do not create a user entry in the /etc/passwd file.
Lock the user’s account.
Unlock the user’s account.
Set the user’s comment field.
Set the user’s expiration date.
Force the creation of the user, even if the username already exists.
Set the user’s time zone.
Set the user’s language.
Additional key feathers
Add and Remove Users in Linux – FAQs
Can I remove many users at once?
Yes, you can remove many users at the same time by using the “userdel” command with their usernames separated by spaces.
In Linux, is it possible to rename a user?
You can rename a user by first creating a new user with the desired username, copying their data and settings, and then deleting the old user account.
Are graphical tools for managing users available in Linux?
Yes, Linux distributions frequently include graphical tools for managing user accounts such as “Users and Groups” or “User Manager” that provide a user-friendly interface.
In Linux, how do I see a list of all users?
You can use the “cat /etc/passwd” command or the “getent passwd” command to display a list of all users registered on the system.
Can I remove a user while deleting their files and home directory?
Yes, you can erase the user’s files and home directory as well as their account by using the “userdel” command with the “-r” option.
Finally, knowing how to Add and Remove users in Linux is critical for effective system administration and user management. Administrators may manage a safe, well-organized, and efficient Linux environment by following the correct procedures, applying best practices, and using the available commands. Please feel free to share your thoughts and feedback in the comment section below.
Greetings, I am a technical writer who specializes in conveying complex topics in simple and engaging ways. I have a degree in computer science and journalism, and I have experience writing about software, data, and design. My content includes blog posts, tutorials, and documentation pages, which I always strive to make clear, concise, and useful for the reader. I am constantly learning new things and sharing my insights with others.
Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.