Introduction
Linux depends on user and group management for structure and security of the system.
Knowing user and group administration is crucial whether you're a system administrator or just a normal user.
It keeps the system well-organized and secure.
Making the most of Linux requires an understanding of handling users and groups.
Why Manage Users and Groups?
Security : Sensitive information is protected when people and groups have the appropriate permissions. This prevents unauthorized users from accessing your files or interfering with your machine.
Resource Sharing : Sharing resources like files and tools is made simple for members of groups. This promotes productive teamwork on projects.
Simplified Administration : Managing the system is made simpler by handling access and permissions through groups. Time and effort can be saved by making modifications for multiple users at once.
Key Concepts in User and Group Management
User Accounts : In Linux, each user has a unique name that identifies them. It is known as a username. A user account, associated with every username, contains vital information such as the password, storage location, and available instructions.
Group Accounts : Users that share similar needs can socialize together in groups, which are similar to clubs. They assist in grouping users according to the tasks they must do. Every group has a list of its members as well as its own name.
Permissions : Permissions in Linux determine who has access to what data and folders. They determine a person's ability to operate, read, and write files. These rights contribute to the overall security and safety.
Superuser (root) : The superuser, commonly referred to as root, is the equivalent of the system administrator. Root is infinitely flexible. Large-scale operations like installing new software or adjusting system settings require it.
Superuser (root) Command
sudo
In Linux,
sudo
functions similarly to a magic word, granting ordinary users the temporary superuser (root) capabilities necessary to perform complex operations like installing programs or altering crucial configurations.Syntax :
sudo apt update
User Account Commands
useradd
useradd
is a command used to create new user accounts.Syntax :
useradd -m <user_account_name>
here,
-m
which stands for "make home directory"Add
sudo
before the useradd command, if it shows "Permission denied".
passwd
passwd
is a command used to create or modify a user's password.Syntax :
passwd <user_account_name>
In the above example, we execute the command for creating the password for the user.
After creating the user password, we can switch the user by using
su <user_account>
here,
su
which stands for "switch user".
How to check user account info
The command
cat /etc/passwd
is used in Linux to display information about user accounts stored in the system's password file.All user accounts are listed, along with information about the username, home directory, default shell, user ID (UID), and group ID (GID).
After executing the command, here you can find in the highlighted section.
userdel
userdel
is a command used to delete a user.Syntax :
userdel <user_account_name>
Add
sudo
before the useradd command, if it shows "Permission denied".After we deleted the user, we can check using the command
cat /etc/passwd
Group Account Commands
groupadd
groupadd
is a command used to create new group accounts.Syntax :
groupadd <group_account_name>
Add
sudo
before the useradd command, if it shows "Permission denied".In this example,we created four users and two groups and will be added four users in different groups.
How to check group account info
The
cat /etc/group
command in Linux is used to display information about groups stored in the system's group file.This command displays a list of all the groups that are present on the system, along with group IDs (GIDs), names, and user memberships in each group.
After executing the command, here you can find in the highlighted section.
gpasswd
This command is used to add a user to a specific group.
Syntax :
gpasswd -a <user_account_name> <group_account_name>
Add
sudo
before the useradd command, if it shows "Permission denied".
we can check by using the command of
cat /etc/group
We can also add "multiple user" in the group at a same time.
Syntax :
gpasswd -M <user_name-1>,<user_name-2> <group_name>
here,
-M
which stands for "Multiple user".
Add
sudo
before the useradd command, if it shows "Permission denied".We can check by using the command
cat /etc/group
groupdel
groupdel
is a command used to delete a group account.Syntax :
groupdel <group_account_name>
Add
sudo
before the useradd command, if it shows "Permission denied".Check if it's deleted or not by using
cat /etc/group
Groups which we created are deleted.
Conclusion
By limiting access, managing users and groups in Linux maintains system security. It is similar to assigning room keys to the appropriate individuals. Proper setup helps in preventing loss and unwanted access.
In a computer system, groups promote collaboration. They enable users with similar needs to work together on projects and exchange resources. This promotes teamwork and speeds up tasks.
Administrators can manage several users at once more easily by managing users and groups. This saves them time and effort because they can modify a large number of users at once.
Administrators of systems can restrict who has access to what information by using user and group management. This means that users only have access to the information that they actually need to perform their jobs.
Linux allows for flexible user and group management that can be adjusted as needed. As the organization expands or undergoes changes, it will be simple to add, modify, or remove users and groups. Over time, this keeps the system secure and functional.