Open In App

How to Rename a Group in Linux?

Last Updated : 14 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Renaming a group in a Linux system is a straightforward but essential administrative task. If 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.

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. Here, we'll show you how to change a group's name in Linux, helping you maintain a well-organized and secure system.

Steps to rename a group in Linux

Renaming a group in Linux requires superuser (root) privileges since you’ll modify system-level files.

1. Go to the terminal window

Open a terminal window on your Linux system. The terminal application is usually found in t 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:

Checking the current group name
Check the current group name.

3. Rename the Group Using groupmod

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:

Rename the Group Using groupmod
Rename the group using the command groupmod.

4. Verify the Name Change

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:

Verify the Name Change
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.


Next Article

Similar Reads