Thursday, December 18, 2008

groups

Creating a group

To create a new group, use the groupadd command: groupadd group

where group specifies the name of the group to be added. Groups are stored in the file etc/group, which can be read by any user but modified only by root. For example, to add a group named newbies, you would enter the following command: groupadd newbies

Deleting a group

To delete a group, user the groupdel command: groupdel group
where group specifies the name of the group to be deleted. For example, to delete the group named newbies, you would enter the following command:
groupdel newbies

Adding a member to a group

To add a member to a group, you use a special form of the adduser command:adduser user group

where user specifies the member and group specifies the group to which the member is added. For example, to add the user newbie01 to the group newbies, you would enter the following command:
adduser newbie01 newbies

Removing a member from a group

Unfortunately, no command removes a user from a specified group. The easiest way to remove a member from a group is by editing the /etc/group file. Here's an excerpt from a typical /etc/group file:
users:x:100:nogroup:x:65534:bmccarty:x:1000:newbies:x:1002:newbie01,newbie02,newbie03

Each line in the file describes a single group and has the same form as other lines, consisting of a series of fields separated by colons (:). The fields are:

Group name: The name of the group.
Password: The encrypted password associated with the group. This field is not generally used, containing an x instead.
Group ID : The unique numeric ID associated with the group.

Member list

A list of user accounts, with a comma (,) separating each user account from the next.
To remove a member from a group, first create a backup copy of the /etc/group file:
cp /etc/group /etc/group.SAVE

The backup can prove helpful if you modify the file incorrectly. Next, open the /etc/group file in a text editor. Locate the line that describes the group and delete the user name and the following comma, if any. Save the file, exit the editor, and check your work.

No comments:

Post a Comment