gpasswd Command Examples in Linux

gpasswd is a command-line utility in Linux and Unix-like systems that allows administrators to administer the /etc/group and /etc/gshadow files. These files contain information about the groups on the system, including the group name, the group ID, and the list of users that are members of the group.

The gpasswd command can be used to perform a variety of tasks related to group management, such as:

  • Adding and removing users from a group
  • Changing the group’s name or ID
  • Changing the group’s password (if the /etc/gshadow file is used)
  • Displaying information about a group

gpasswd Command Examples

1. Define group administrators:

# sudo gpasswd -A user1,user2 group

2. Set the list of group members:

# sudo gpasswd -M user1,user2 group

3. Create a password for the named group:

# gpasswd group

4. Add a user to the named group:

# gpasswd -a user group

5. Remove a user from the named group:

# gpasswd -d user group
Related Post