How to use gpasswd command on Ubuntu Linux with examples

programmer 1653351 640 1
programmer 1653351 640 1

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.

New users and students learning to use Linux should start on Ubuntu Linux OS. Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.

When you’re ready to learn how to use the gpasswd commands, follow the guide below:

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:

Posted by
Richard

I love computers; maybe way too much. What I learned I try to share at geekrewind.com.

1 Comment

  1. 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: