The gpasswd command Explained
The gpasswd command sets a group password. A group password prevents non-group member users from changing their primary group to the password-protected group. Without a password, a group does not stop users from joining it. If we configure a group password, the group authenticates non-group users with the group password before allowing them in the group. The gpasswd command sets a group password.
The gpasswd command syntax
The gpasswd command uses the following syntax.
#gpasswd [option] group
The gpasswd command options
| Short option | Long option | Description |
| -a | --add | Add the user to the named group. |
| -d | --delete | Remove the user from the named group. |
| -h | --help | Display help message and exit. |
| -Q | --root | Apply changes in the specified directory and use the configuration files from the directory. |
| -r | --remove-password | Remove the password from the group. The group password will be empty. Only group members can use newgrp to join the named group. |
| -R | --restrict | Restrict access to the named group. It sets the group password to !. Only group members with a password can use newgrp to join the named group. |
| -A | --administrators | Set the list of administrative users. |
| -M | --members | Set the list of group members. |
The gpasswd command example
- Add two new users: user1 and user2.
- List the last two entries of the /etc/passwd file.
- View the last two entries of the /etc/group file.
- Add a new group: usergroup.
- List the last entry of the /etc/gshadow file.
- Add the first user to the group.
- Switch to the first user account and change the default group to usergroup.
- Verify the user can change his default group.
- Exit from the first user and switch to the second user account.
- Change the default group to usergroup.
- Verify the user cannot change his default group.
- Exit from the second user account and set a group password.
- Switch to the second user account again and change the default group to usergroup.
- Verify the user can change his default group.
#useradd user1 #useradd user2 #tail -2 /etc/passwd #tail -2 /etc/group #groupadd usergroup #usermod -G usergroup user1 #su user1 #tail -1 /etc/passwd #tail -1 /etc/group

The gpasswd command help options
If you need help with the chage command, use the -h or --help option. When used with this option, it lists a summary of all options and their usage.

If you need a detailed overview of this command and all options, use its manual pages. The following command displays the manual of this command.

The gpasswd command configuration files
The gpasswd command assigns a password to the group. The /etc/gshadow file saves group passwords. The /etc/group file saves group information.
This tutorial is part of the tutorial series 'Linux User and Group Management Explained with Examples'. Other parts of this series are the following.
Chapter 01 Difference between the root user and super (sudo) user
Chapter 02 Linux User Management Explained with Examples
Chapter 03 Linux Group Management Explained with Examples
Chapter 04 Password aging policy Explained with chage command
Chapter 05 The /etc/group File Explained
Chapter 06 The /etc/gshadow File Explained
Chapter 07 The /etc/passwd file in Linux Explained with Examples
Chapter 08 The /etc/shadow file in Linux Explained with Examples
Chapter 09 The useradd command Explained
Chapter 10 The gpasswd command Explained
Chapter 11 The chage command Examples and Usages
Conclusion
By understanding the gpasswd command, you can effectively configure a group password and enhance the security of groups on Linux systems. Mastering the gpasswd command is essential for maintaining a secure and well-managed Linux environment. This tutorial presented a detailed overview of the gpasswd command and its options. It also explained common usages of this command through examples.
Author Laxmi Goswami Updated on 2026-04-13