The gpasswd
command is used in Linux systems to administer /etc/group
and /etc/gshadow
files. It allows users to manage group memberships, add or remove users from groups, and set group passwords.
The basic syntax of the gpasswd
command is as follows:
gpasswd [options] [arguments]
-a, --add USER GROUP
: Adds the specified user to the specified group.-d, --delete USER GROUP
: Removes the specified user from the specified group.-r, --remove GROUP
: Removes the specified group.-P, --password PASSWORD
: Sets the password for the group.-h, --help
: Displays help information about the command.To add a user named john
to a group called developers
, you would use:
gpasswd -a john developers
To remove a user named john
from the developers
group, the command would be:
gpasswd -d john developers
To set a password for a group named admins
, you can use:
gpasswd -P mypassword admins
To remove a group called oldgroup
, you would execute:
gpasswd -r oldgroup
gpasswd
with caution, especially when removing users or groups, as these actions can affect system access.groups
command followed by the username.