Saturday, 11 June 2011

Create, delete and modify local groups and group memberships

Another reasonably simple objective:

Create groups:

To create a group simply run the following command:
groupadd groupname
Delete group:

To delete a group simply run the following command:
groupdel groupname
Modify groups and group memberships:

The first objective can be achieved with the groupmod command, whereas the second can be achieved with usermod as explained in the previous post, or with the groupmems command.

Say you want to change the name of a group:
groupmod -n newgroupname oldgroupname
or change the group id :
groupmod -g 1234 groupname
Group memberships can be changed with the groupmems command. To add users to a group issue the following command:
groupmems -g groupname -a username
and to delete them from the group:
groupmems -g groupname -d username
You can purge a group with the -p switch and the -l switch will list the users belonging to that group, e.g.:
groupmems -g groupname -l
The group file is in /etc/group, but you could also list its contents with the getent command:
getent group
This commands works for users (passwd or shadow), hosts and a few others, as detailed in the man page.

No comments:

Post a Comment