Friday 26 August 2011

Group Membership in Linux

Syntax:- 

[root@localhost~]# gpasswd <option> <arguments> <groupname>

Options:

-M -- Add multiple users to a group
-A -- Add a group Administrator
-a -- Add a single user to a group
-d -- Delete a user from a group


Example:- Add multiple users (ravi, sunil) to the group marketing
Note: Before doing this the group marketing should be exists.

[root@test119 ~]# gpasswd -M ravi,sunil marketing

To check if the users are added to the group

[root@test119 ~]# grep marketing /etc/group

marketing:x:2006:ravi,sunil


Example:- Add user rani as the administrator for the group marketing

[root@test119 ~]# useradd rani
[root@test119 ~]# gpasswd -A rani marketing

To check if rani has been added as the administrator for the group marketing

[root@test119 ~]# grep marketing /etc/gshadow
marketing:!:rani:ravi,sunil


Example:- Add a user ahmed to the group marketing

[root@test119 ~]# useradd ahmed
[root@test119 ~]# gpasswd -a ahmed marketing
Adding user ahmed to group marketing

To check if the user has been added to the group

[root@test119 ~]# grep marketing /etc/group
marketing:x:2006:ravi,sunil,ahmed


Example:- Delete the user ravi from the group marketing

[root@test119 ~]# gpasswd -d ravi marketing
Removing user ravi from group marketing

To check if the user has been deleted from the group

[root@test119 ~]# grep marketing /etc/group
marketing:x:2006:sunil,ahmed

Creating a user along with it Group Membership

Example:- Creating a user sri with primary group as hr and member of the group finance

[root@test119 ~]# groupadd hr
[root@test119 ~]# groupadd finance
[root@test119 ~]# useradd -g hr -G finance sri

To check if the user has been created along with group membership

[root@test119 ~]# grep sri /etc/passwd /etc/group
/etc/passwd:sri:x:2008:2009::/home/sri:/bin/sh
/etc/group:finance:x:2010:sri

Adding or Modifying or Deleting users and groups using a graphical tool

Open the graphical too using command


[root@test119 ~]# system-config-users &


0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews