gpasswd command
What is the gpasswd
command in Linux, and what does it do?
The `
gpasswd`
command is a Linux utility used to administer group passwords. It allows users to add or remove members from a group, set or change the group password, and manage group administrators.
How do I add a user to a group using the gpasswd
command?
To add a user to a group, you can use the following
syntax:
gpasswd -a [user] [group]
For example: to add a user named “john” to the group “developers”, you would use
gpasswd -a john developers
Can I set or change the password for a group using gpasswd
?
Yes, you can set or change the password for a group using the `
-r`
option followed by the group name.For example: To set or change the password for the group “developers”, you would use
gpasswd -r developers
You will then be prompted to enter the new password.
How do I remove a user from a group with the gpasswd
command?
To remove a user from a group, you can use the following
syntax:
gpasswd -d [user] [group]
For example: to remove the user “jayesh” from the group “developers”, you would use
gpasswd -d jayesh developers
Are there any advanced options available with the gpasswd
command?
Yes, `
gpasswd`
provides several advanced options. For example, you can designate a group administrator with the `-A
option followed by the username, or remove an administrator with the `-R`
option. Additionally, you can list group members with the `-M`
option followed by a list of usernames.
gpasswd Command in Linux with examples
gpasswd command is used to administer the /etc/group and /etc/gshadow. As every group in Linux has administrators, members, and a password. It is an inherent security problem as more than one person is permitted to know the password. However, groups can perform co-operation between different users. This command assigns a user to a group with some security criteria. This command is called by a group administrator with a group name only which prompts for the new password of the group. System administrators can use the -A option to define group administrator(s) and -M option to define members. They have all the rights of the group administrators and members.