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, –restrict | Use the -R or –restrict option to restrict access to GROUP to its members |
-M, –members USER | Use the -M or –members USER to set the list of members of GROUP |
-A, –administrators ADMIN | set 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:
Leave a Reply Cancel reply