
Managing Users and Groups in Linux:
Every computer system, including Linux, has users. Yes, you read that right; you are a user too! In this blog post, we’ll dive into the fascinating world of Linux users and groups and explore how you can manage them like a true superhero.
Adding a User
Adding a user to your Linux system is a straightforward process, but there’s a catch. Only the all-powerful ‘root’ user can add new users.
However, before we add our new user, let’s take a moment to understand who or what ‘root’ is. ‘root’ is another user on your system, but it holds superuser privileges. To add a user, we need to use ‘sudo‘ which stands for “superuser do.”
sudo adduser username

your new user has been added to the system. But where can you find all the users on your Linux machine? You can check by using the following command:
cat /etc/passwd

You can see User with the name “david”. the ‘x’ you see under the ‘User’ column represents the password. The actual passwords are stored in /etc/shadow and are hidden from view.
To get more information about users, you can check /etc/shadow. Additionally, you’ll notice two numbers associated with each user: the User ID (UID) and the Group ID (GID). When you create a user in Linux, it automatically creates a user and a group with the same name.
Customizing User
Linux gives us the flexibility to customize user properties. For example, we can change the shell assigned to a user by using the following command:
sudo usermod username --shell /bin/bash
To change the username itself:
sudo usermod -l newusername oldusername
You can also perform more advanced user modifications using
sudo usermod -h
Managing Groups
Linux also allows you to create and manage groups. To create a new group, use the following command:
sudo groupadd groupname
To view all the groups on your system:
cat /etc/group
But what’s the use of a group without power? To grant superpowers to a group, add it to the sudoers file:
Open sudoiers file by following command:
sudo visudo
Add the following line to give the group unlimited power:
%groupname ALL = NOPASSWD:ALL
Now, any member of that group can execute superuser commands without a password prompt.
Adding Users to Groups
The real fun begins when you start adding users to groups. Use this command to add a user to a group:
sudo usermod -aG groupname username
The -aG flag appends the user to the specified group, while ensuring they remain members of their existing groups.
Removing Users from Groups
To remove a user from a group:
sudo gpasswd -d username groupname
Deleting Users and Groups
Finally, when you’re done with a user, you can delete them using:
sudo userdel username
And to delete a group:
sudo groupdel groupname
In the world of Linux, managing users and groups is crucial for system security and organization. With these commands at your fingertips, you can wield the power of the gauntlet and make your Linux system dance to your tune.
sudo usermod -l newusername oldusername



