Open In App

How to Rename a Group in Linux?

Last Updated : 15 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Renaming a group in a Linux system is a straightforward but essential administrative task. Whether you’re reorganizing your user management structure or enhancing security measures, this quick guide will walk you through the simple steps to rename a group. Linux provides a powerful command, ‘groupmod’ to make this process smooth and efficient. In this article, we’ll show you how to change a group’s name in Linux, helping you maintain a well-organized and secure system.

Using the command ‘groupmod’, a group can be renamed in Linux. This command changes the group’s definition by modifying an appropriate entry in its database.

To rename a group, here are the steps:

1. Go to the terminal window:

Open a terminal window on your Linux system. You can usually find the terminal application in your system’s applications menu or by pressing a keyboard shortcut like `Ctrl+Alt+T`.

2. Check the current group name.

Before renaming a group, it’s a good practice to verify the current name of the group you want to change. To do this, you’ll use the cat and grep commands.

To check the current group name, use the following command:

cat /etc/group | grep [OLD_GROUPNAME]

Here:

  • cat: concatenate files and print on the standard output.
  • /etc/group: The system file that contains group attributes.
  • grep: Searches for patterns in the specified file(s).
  • OLD_GROPNAME: Replace this with the current name of the group you want to rename.

Example:

Screenshot-2023-09-29-142528-min

Check the current group name.

3. Use the command ‘groupmod’ to rename the group along with ‘-n’:

To rename a group, you’ll use the groupmod command with the -n option to specify the new group name. You’ll also need to provide the old group name, and you’ll typically need superuser privileges.

To rename a group, use the following command:

sudo groupmod  -n [NEW_GROUPNAME] [OLD_GROUPNAME]

The sudo command is required because the groupmod command needs root privileges to modify the group database.

Here:

  • sudo: Allows you to execute a command with superuser privileges.
  • groupmod: The command for modifying group definitions on the system.
  • -n: This option indicates the new name for the group.
  • NEW_GROUPNAME: Replace this with the desired new name for the group.
  • OLD_GROUPNAME: Replace this with the current name of the group you want to rename.

Example:

Screenshot-2023-09-27-214434-min

Rename the group using the command groupmod.

4. Verify that the name has been change successfully.

After running the groupmod command, you should verify that the group name has been changed successfully.

To verify that the group name has been changed successfully, use the same command that you used in step 2, but with the new group name:

cat  /etc/group | grep [NEW_GROUPNAME]

Here:

  • cat: Concatenates and displays the content of files.
  • /etc/group: The system file that contains group attributes.
  • grep: Searches for patterns in the specified file(s).
  • NEW_GROPNAME: Replace this with the new name of the group.

Example:

Screenshot-2023-09-29-144410-min

Verify that the name has been changing successfully.

Now, we confirm that the group name has been successfully changed.

By following these steps, you can safely and effectively rename a group on your Linux system using the terminal. Make sure to replace [OLD_GROUPNAME] and [NEW_GROUPNAME] with the actual names of the group you want to rename and the desired new name, respectively.

Conclusion:

The simple process of renaming a group in Linux can be accomplished by using the ‘groupmod’ command. You can change a group’s name on your Linux system through the steps listed above. It can be particularly useful for management or administration. You must always verify that the change has been successful in reassigning this group, and maintain its integrity on Linux.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads