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.

Basic Syntax of gpasswd Command:

The basic syntax of the gpasswd command is straightforward:

gpasswd [option] [group]

Here,

[options] represent various command-line flags that modify the behavior of the gpasswd command.

[group] specifies the name of the group to be modified.

Options in gpasswd Command:

Here only -A and -M options can be combined.

  • -a, --add : This option is used to add a user to the named group.
  • -d, --delete : It is used to remove a user from the named group.
  • -r, --remove-password : It is used to remove the password from the named group.
  • -R, --restrict : This option will restrict the access to the named group.
  • -A, --administrators : Set the list of administrative users.
  • -M, --members : It set the list of group members.
  • -h, --help : It displays the help message and exit.
    $ sudo gpasswd -h 

Examples of gpasswd Command :

Creating a group and adding a user to it. After that deleting the user.

  • Adding a group named as geeks.
    $ sudo groupadd geeks

    adding group name

    adding group name

  • To display the created group with their id you can use:
    $cat /etc/group

    listing groups

    listing groups

  • Now the group geeks is added so now execute command under to add the user to group geeks:
    $ sudo gpasswd -a umang geeks

  • Deleting the created user from group geeks.
    $ sudo gpasswd -d umang geeks

Conclusion

In conclusion, the gpasswd command in Linux serves as a crucial tool for managing group passwords and membership, addressing inherent security challenges by enabling administrators to control access effectively. Through its simple syntax and various options like adding or removing users, setting passwords, and designating administrators and members, gpasswd empowers system administrators to enhance security and collaboration within the Linux environment.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值