LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to add user into group. (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-add-user-into-group-862556/)

gardenair 02-14-2011 05:03 AM

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

EricTRA 02-14-2011 05:04 AM

Hello,

Have a look at the usermod command:
Code:

man usermod
Kind regards,

Eric

sycamorex 02-14-2011 05:06 AM

http://www.yolinux.com/TUTORIALS/Lin...ingGroups.html

gardenair 02-15-2011 12:49 AM

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

micxz 02-15-2011 12:50 AM

You can see users in /etc/passwd and groups in /etc/group

EricTRA 02-15-2011 12:58 AM

Quote:

Originally Posted by gardenair (Post 4258647)
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

gardenair 02-15-2011 04:26 AM

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 ?

EricTRA 02-15-2011 04:32 AM

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

gardenair 02-17-2011 05:32 AM

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 ?

sandy.bhadoriya 02-17-2011 05:45 AM

useradd -G marketing smith

I think the above should work perfectly for having a secondary group for the user smith

EricTRA 02-17-2011 08:52 AM

Quote:

Originally Posted by gardenair (Post 4261377)
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

Reuti 02-17-2011 08:59 AM

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.


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