Linux command
gpasswd 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Example
sudo gpasswd -A [user1,user2] [group]
Example
sudo gpasswd -M [user1,user2] [group]
Example
gpasswd [group]
Add
gpasswd -a [user] [group]
Remove
gpasswd -d [user] [group]
说明
gpasswd administers /etc/group and /etc/gshadow files. It is used to add and remove users from groups, set group administrators, and manage group passwords. Group administrators (set with -A) can add or remove members without root privileges, delegating group management to trusted users. Group passwords (rarely used) allow non-members to temporarily join a group using the newgrp command.
参数
- -a, --add _USER_
- Add user to the group
- -d, --delete _USER_
- Remove user from the group
- -A, --administrators _USER,..._
- Set list of group administrators
- -M, --members _USER,..._
- Set list of group members (replaces existing)
- -r, --remove-password
- Remove group password
- -R, --restrict
- Restrict access to group (only members can use newgrp)
FAQ
What is the gpasswd command used for?
gpasswd administers /etc/group and /etc/gshadow files. It is used to add and remove users from groups, set group administrators, and manage group passwords. Group administrators (set with -A) can add or remove members without root privileges, delegating group management to trusted users. Group passwords (rarely used) allow non-members to temporarily join a group using the newgrp command.
How do I run a basic gpasswd example?
Run `sudo gpasswd -A [user1,user2] [group]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -a, --add _USER_ do in gpasswd?
Add user to the group