How to Use gpasswd for User Management

The gpasswd command in Linux is used to manage /etc/group and /etc/gshadow files, altering users and groups via the command line. This involves administering encrypted groups and group information through the /etc/group and /.etc/gshadow files. Syntax and options for the gpasswd command are provided, along with examples of the command’s application in Ubuntu Linux. New…

This article explains how to use the gpasswd command on Ubuntu Linux.

The gpasswd command is used to administer /etc/group and /etc/shadow files. Like using your mouse and keyboard to manage users and groups, the gpasswd is how to do it on the command line.

This command-line tool allows you to manage user groups and their members by adding or removing users to or from groups. The /etc/group file contains group information, while the /etc/gshadow file contains encrypted group information.

Using the gpasswd command, you can add or remove users to or from a group, set or change a group’s password, and even specify group administrators and restrict access to specific groups. It is a powerful tool that helps system administrators manage user and group accounts on Ubuntu Linux.

About the gpasswd command:

The gpasswd command is used to administer /etc/group and /etc/gshadow files. Like using your mouse and keyboard to manage users and groups, the gpasswd is how to do it on the command line. The /etc/group file contains group information, and the /etc/gshadow file contains encrypted groups.

The following configuration variables in /etc/login.defs change the behavior of gpasswd. Then, edit that file to configure other settings.

Syntax:

The syntax is the rule and format of how the gpasswd command can be used. The syntax can be reordered. But a straight format must be followed.,.

Below is an example syntax of how to use the gpasswd command.

gpasswd [OPTION]. GROUP.

Options:

The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the command. They are separated by spaces and followed after the command options.

Below are some options for the gpasswd command:

    GROUP.Replace GROUP.. with the name of the account you want to manage.
-a, –add USER
Use the -a or –add USER option to add a to a GROUP. Replace USER with the user account you wish to add to the group
-d, –delete USER           Use the -d or –delete USER option to remove a user from a GROUP. Then, replace USER with the user you wish to remove.
-R, –restrictUse the -R or –restrict option to restrict access to GROUP to its members
 -M, –members USERUse the -M or –members USER to set the list of members of GROUP
-A, –administrators ADMINset the list of administrators for GROUP. ADMIN with the name or the user account.

Examples:

Below are some examples of how to run and use the gpasswd on Ubuntu Linux.

If you want to add a user named John to the Players group, run the commands below.

gpasswd -a john players

To give John administrative rights to manage the Player’s group and run the commands.

gpasswd -A john players

The commands above make John an admin of the Player’s group.

If you’re not logged in as a root account, you may have to use the sudo command.

sudo gpasswd -A john players

To remove John’s account from the group, run the commands below.

sudo gpasswd -d john players

When you run gpasswd with the –help option, you’ll see the help text below:

Usage: gpasswd [option] GROUP

Options:
  -a, --add USER                add USER to GROUP
  -d, --delete USER             remove USER from GROUP
  -h, --help                    display this help message and exit
  -Q, --root CHROOT_DIR         directory to chroot into
  -r, --remove-password         remove the GROUP's password
  -R, --restrict                restrict access to GROUP to its members
  -M, --members USER,.        set the list of members of GROUP
  -A, --administrators ADMIN,.
                                set the list of administrators for GROUP
Except for the -A and -M options, the options cannot be combined.

That’s it!

I hope you like it, and please come back soon for more Ubuntu Linux commands!

You may also like the commands below:

Richard Avatar

Comments

  1. Nigel Horne Avatar
    Nigel Horne

    When I try “gpasswd -a $user $group” I get a usage message.

    # gpasswd –-add HIDDEN HIDDEN
    Usage: gpasswd [option] GROUP

    Options:
    -a, –add USER add USER to GROUP
    -d, –delete USER remove USER from GROUP
    -h, –help display this help message and exit
    -Q, –root CHROOT_DIR directory to chroot into
    -r, –delete-password remove the GROUP’s password
    -R, –restrict restrict access to GROUP to its members
    -M, –members USER,… set the list of members of GROUP
    -A, –administrators ADMIN,…
    set the list of administrators for GROUP
    Except for the -A and -M options, the options cannot be combined.

Leave a Reply

Your email address will not be published. Required fields are marked *


Exit mobile version