User and Group Management in Linux


 Introduction

Managing users and groups is a core task for Linux system administrators. Proper user management ensures system security and controlled access to resources.


Step 1: Add a New User

Use the useradd command to create a new user.


sudo useradd username


➡️ Replace username with the actual user name.


Step 2: Set Password for User

Assign a password using the passwd command.


sudo passwd username


➡️ The system will prompt you to type and confirm the password.


Step 3: Delete a User

Remove a user account when no longer needed.


sudo userdel username


➡️ Add -r to also remove the user’s home directory.


Step 4: Add a Group

Create a new group with the groupadd command.


sudo groupadd groupname


➡️ Replace groupname with your desired group.


Step 5: Add User to a Group

Use the usermod command to add a user to a group.


sudo usermod -aG groupname username


➡️ The -aG option appends the user to the group.


Step 6: View User Information

Check user details such as UID, GID, and group memberships.


id username


➡️ This will display the user’s UID, GID, and group membership list.


Conclusion

User and group management is essential for keeping your Linux system secure and organized. In the next post, we will explore file permissions and ownership to further control access.

Comments