Day 21 || Managing Groups and Users in a Linux DevOps Environment

Day 21 || Managing Groups and Users in a Linux DevOps Environment

This step-by-step guide will walk you through creating, deleting, modifying groups, and adding/removing users, as well as changing group names and IDs in a Linux-based DevOps environment.

Step 1: Creating a New Group

To create a new group, follow these instructions:

  1. Open a terminal on your Linux machine.

  2. Use the groupadd command to create a new group. Replace groupname with the desired name for your group:

sudo groupadd groupname

Ensure that you run this command with superuser privileges by using sudo.

Step 2: Deleting a Group

To delete an existing group, use the groupdel command:

  1. Open a terminal on your Linux machine.

  2. Execute the following command, replacing groupname with the group you want to delete:

sudo groupdel groupname

Remember to use sudo to run this command with superuser permissions.

Step 3: Modifying Group Properties

You can modify group properties, such as the group name, using the groupmod command:

  1. Open a terminal on your Linux machine.

  2. To change the name of an existing group from oldgroupname to newgroupname, run:

sudo groupmod -n newgroupname oldgroupname

Ensure that you use sudo to execute this command with superuser privileges.

Step 4: Adding a User to a Group

To add a user to an existing group, you can use the usermod command:

  1. Open a terminal on your Linux machine.

  2. Execute the following command to add a user (replace username with the actual username) to a group (replace groupname with the desired group):

sudo usermod -aG groupname username

Make sure to use sudo for superuser access.

Step 5: Removing a User from a Group

To remove a user from a group, use the gpasswd command:

  1. Open a terminal on your Linux machine.

  2. Run the following command to remove a user (replace username with the actual username) from a group (replace groupname with the desired group):

sudo gpasswd -d username groupname

Don't forget to use sudo for superuser permissions.

Step 6: Changing Group Name and ID

Changing the group name and ID can be done using the groupmod command:

  1. Open a terminal on your Linux machine.

  2. To change the name of an existing group from oldgroupname to newgroupname, run:

sudo groupmod -n newgroupname oldgroupname

For changing the group ID, use the groupmod command as follows:

sudo groupmod -g newgroupid groupname

Make sure to use sudo for superuser access.


Now that you've learned the essentials of managing groups and users in a Linux DevOps environment, try out these commands in your own environment to gain hands-on experience.

Home Activity:

Create a new group, add a user to it, remove the user from the group, and change the group's name and ID. This practical exercise will reinforce your understanding of group and user management in DevOps.

Did you find this article valuable?

Support Aqib Hafeez(DevOps enthusiast) by becoming a sponsor. Any amount is appreciated!