Home   |   Guides and Tutorials   |   What's New?   |   Comments   |   About
 

groupadd: Adding A User Group

by Tammy Fox
Last Modified: Wednesday, 19-May-2004 11:55:32 EDT

Introduction
    A group is a way to organize users on any Unix-based machine including Linux. Members of a group can share files and directories. For instance, if you have two webmasters of an internet site and both need access to read/write to the files and directories for the website, the two webmasters could be members of the same group and have equal permissions to the files and directories within the group.

Using the Command Line
    Note: You must have root access to add a group. If you are logged in as a regular user and know the root password, you can type the command su. This will prompt you for a password. Enter the root password correctly and you will have root priviledges until you type exit. Typing exit will take you back to regular user mode.
    After changing to root, the command groupadd can be used to add groups to your machine. In Red Hat Linux, the groupadd command is located in the /usr/sbin directory. To invoke the command you might have to type /usr/sbin/groupadd (the full path) if /usr/sbin is not in your path. For further information about adding to your path see the Setting Your Path guide.
    Thus, to add a group called linuxhq, type the command /usr/sbin/groupadd linuxhq. This will add a line to the /etc/group file. After the group is added, you must add users to that group. To do so, edit the /etc/group file. At the end of the line beginning with the name of your new group, add the names of the users separated by commas. For example, adding the users tchin and bfox to the linuxhq group would look like this:
linuxhq:x:500:tchin,bfox

Using Linuxconf
    Note: You must have root access to add a group. If you are logged in as a regular user and know the root password, you can type the command su. This will prompt you for a password. Enter the root password correctly and you will have root priviledges until you type exit. Typing exit will take you back to regular user mode.
    After changing to root, invoke the Gnome Linuxconf GUI Tool by typing linuxconf. In Red Hat Linux, linuxconf is found in the /bin directory. Thus, if it is not in your path, you must type /bin/linuxconf. For further information about adding to your path see the Setting Your Path guide. Once linuxconf has started, choose Config->User Accounts->Normal->Group Definitions from the menu tree on the left. After choosing Group Definitions, your screen should look like below.



    To add a group from here, click Add. A new screen should appear. From the group specifications menu, enter the name of the group you wish to add such as linuxhq. You can leave the group ID as whatever is automatically generated. In the alternate members field, list the users you wish to be in the group, separated by spaces. The screen should then look like below:



    Click Accept, and you will be taken back to the User Groups menu.



    You will know that the group has been added because it will now appear in the group list. Click Quit to exit the User Groups section. Then, click Quit again and activate changes, and you can then begin using your new users group.

Switching to a Different Group
    If you are a member of more than one group, you can use the newgrp command to change to that group. For example to change to the linuxhq group, you would type the command newgrp linuxhq. From then on until you type exit you will be a member of the linuxhq group. This means that any file or directory you write will have the group linuxhq. Also, you will have access to any files with read/write permissions to the linuxhq group. See the newgrp: Changing to Another User Group guide for more information on using the newgrp command.

What's Related


All Rights Reserved Linux Headquarters © 2000-2007
Linux is a registered trademark of Linus Torvalds
All logos are registered trademarks of their respective owners
Last modified: Wednesday, May 19, 2004