LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-14-2011, 05:03 AM   #1
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 570

Rep: Reputation: 31
How to add user into group.


I want to add a user "smith" into marketing group using terminal.Please guide me that how can I do it ?

thanks
garden
 
Old 02-14-2011, 05:04 AM   #2
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hello,

Have a look at the usermod command:
Code:
man usermod
Kind regards,

Eric
 
Old 02-14-2011, 05:06 AM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,564
Blog Entries: 1

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
http://www.yolinux.com/TUTORIALS/Lin...ingGroups.html
 
Old 02-15-2011, 12:49 AM   #4
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 570

Original Poster
Rep: Reputation: 31
well I have use the command

[root@localhost home]# usermod -d marketing smith

How can I check that in marketing group there is a smith user.Which file should I see for it ?
thanks
garden
 
Old 02-15-2011, 12:50 AM   #5
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
You can see users in /etc/passwd and groups in /etc/group
 
Old 02-15-2011, 12:58 AM   #6
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Quote:
Originally Posted by gardenair View Post
well I have use the command

[root@localhost home]# usermod -d marketing smith

How can I check that in marketing group there is a smith user.Which file should I see for it ?
thanks
garden
Hi,

Have you looked at the man page of usermod?
Code:
-d, --home HOME_DIR
           The user's new login directory.
The -d option is used to set a new home directory. If you want to add a user to an additional group you use the -G option:
Code:
 -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
           A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option.

           If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list.
Also you can check group membership simply by using:
Code:
id <username>
which will give you something like:
Code:
uid=1000(eric) gid=1000(eric) groups=1000(eric),4(adm),7(lp),21(fax),27(sudo)
Kind regards,

Eric
 
Old 02-15-2011, 04:26 AM   #7
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 570

Original Poster
Rep: Reputation: 31
well one thing confusing me that when i create a new user like xyz user I can see its name in /etc/group file as
xyz:x:501
and if I add xyz user into marketing then in /etc/group file it show
marketing:x:502:

The question is when a new user is just created by its entry is also shown in /etc/group file .What is the reason ?
 
Old 02-15-2011, 04:32 AM   #8
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hello,

When you create a new user, automatically a group with the same name gets created. This groupID (gid) gets used for example when the user creates a file. Then the default group association of that file will be that same groupID. Hope that helps. You can change that group association at any time. You can also add a user to additional groups as explained above. Sycamorex pointed you to a very good tutorial in post #3, I suggest you read it, it contains very good information.

Kind regards,

Eric
 
Old 02-17-2011, 05:32 AM   #9
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 570

Original Poster
Rep: Reputation: 31
thanks for your reply. I have review the site as well. Well I am showing following how I add "john" Primary group and then secondary group ?

Creating user
Code:
#adduser john
Now adding password
Code:
#passwd john
Now adding into group
Code:
#groupadd fisrgroup
Now adding user join into group i.e firstgroup
Code:
#usermod -d firstgroup john
for secondary group
Code:
#groupadd secondgroup
Creating users
Code:
#adduser john,jill,jack,harry
Now adding into group
Code:
#groupadd secondgroup
Now adding user john,jill,jack,harry into group i.e secondgroup

Code:
#usermod -d secondgroup john,jill,jack,harry
please guide me that my steps are correct or not ?
 
Old 02-17-2011, 05:45 AM   #10
sandy.bhadoriya
Member
 
Registered: Dec 2010
Posts: 31

Rep: Reputation: 3
useradd -G marketing smith

I think the above should work perfectly for having a secondary group for the user smith
 
Old 02-17-2011, 08:52 AM   #11
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Quote:
Originally Posted by gardenair View Post
Code:
#usermod -d firstgroup john
Code:
#usermod -d secondgroup john,jill,jack,harry
Hello,

Why are you sticking to -d as parameter to usermod? Haven't you read my post (#6)? Or do you have a different version of usermod that switched -G for -d?

Kind regards,

Eric
 
Old 02-17-2011, 08:59 AM   #12
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
The problem with the man page might be that the options -A and -R to add/remove groups from the supplementary groups list are not listed. Or is this only an undocumented openSUSE extension?

But I also don't get the OP whether the user "smith" in question already exists and should only be added to the group "marketing" or whether he must be created completely.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to list user in Linux box, add an user to a group! steady_lfcfan Linux - Newbie 12 01-27-2013 01:14 PM
how to add a user to a new group? emanresu Linux - Newbie 5 11-21-2005 08:18 AM
add user to the group ashley75 Linux - General 4 03-30-2005 02:42 PM
how do i add user to a group jogurt666 Linux - General 2 04-02-2004 10:05 PM
how to add a user to a certain group? feetyouwell Linux - Software 2 01-13-2004 11:56 AM


All times are GMT -5. The time now is 11:41 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration