English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux gpasswd command

Linux Command大全

Linux gpasswd is a workgroup file under Linux /etc/group and /etc/gshadow is a management tool used to add a user to a group or remove a user from a group.

Syntax

gpasswd [options] groupname

Optional parameters:

  • -a: Add a user to a group;
  • -d: Remove a user from a group;
  • -A: Specify administrator;
  • -M: Specify group members and-The usage of A is similar;
  • -r: Delete password;
  • -R: Restrict user login to the group, only group members can use newgrp to join the group.

Online Examples

If there is a peter account on the system, and the account itself is not a member of the groupname group, you need to enter the password when using newgrp.

gpasswd groupname

This allows the user to temporarily join the group and after that, the files created by peter will also be groupname. So this method can temporarily allow peter to create files using other groups instead of peter's own group.

So using gpasswd groupname to set a password is to allow those who know the group password to temporarily switch to the group with groupname functions.

gpasswd -A peter users

In this way, peter is the administrator of the users group and can perform the following operations:

gpasswd -a mary users
gpasswd -a allen users

NoteTo add a user to a specific group, you can use usermod -The command G group_name user_name can add a user to the specified group, but the previously added groups will be cleared.

So if you want to add a user to a group while retaining the previously added groups, please use the gpasswd command to add the operation user:

gpasswd -a user_name group_name

Linux Command大全