LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 05-13-2009, 03:14 AM   #1
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Rep: Reputation: 51
Difference between useradd -g and -G?


Code:
[root@receiver ~]# groupadd devel
[root@receiver ~]# useradd -g developers resd

[root@receiver ~]# id resd
uid=514(resd) gid=514(developers) groups=514(developers)
[root@receiver ~]# groupadd testing
[root@receiver ~]# useradd -G testing resd
useradd: user resd exists
[root@receiver ~]# useradd -G testing rest
[root@receiver ~]# id rest
uid=515(rest) gid=517(rest) groups=517(rest),516(testing)
[root@receiver ~]#
Whats the diff between -G and -g?
Manual says -g represent primary Group Whats that?
 
Old 05-13-2009, 03:23 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

A user needs to be part of at least one group (the primary group), this is set by the -g option. Only one group is allowed (ie: -g main vs -g main other1 [last example is not cirrect, first is])

A user can be part of other groups, which is set by the -G option. More groups are allowed (ie: -G other1 and -G other1 other2 .... are both syntactically correct).

You can see which group(s) a user belongs to by: id <username>

Example:

$ id druuna
uid=500(druuna) gid=500(internet) groups=500(internet),52(audio),53(video),60(usb),75(cdrom),76(cdrw),400(users),600(visitor),700(repo rter),800(jmeter)

The initial, primary group is also visible in the groups output.

Hope this clears things up a bit.
 
Old 05-13-2009, 03:26 AM   #3
maxy7710
Member
 
Registered: Jan 2008
Location: Mumbai, india
Distribution: REDHAT, FEDORA,SUSE, UBUNTU, ORACLE ENTERPRISE LINUX & SOLARIS 10
Posts: 130

Rep: Reputation: 17
By default every user will have his primary group & if no group name is mentioned while creating the user then default primary group is same as his username.

Secondary group is used when multiple people have to work on a same project & they require similar access to a particular folder.

i.e all people from group abc are accessing folder1 then we can give permissions rwx as per needs to the group of the folder no need to give permission to others, but abc should be the default group for that folder.
 
Old 05-13-2009, 03:30 AM   #4
MoonMind
Member
 
Registered: May 2005
Location: Switzerland
Distribution: Ubuntu
Posts: 448

Rep: Reputation: 38
If you do ls -l in a directory, you'll see something like this:
Code:
-rw-r--r--  1 user group 5120 2009-05-13 19:30 filename
- user being the user who ones the file, group indicating the primary group the user belongs to - on most systems, it defaults to the user's own group (i.e. it's the same as user, but that depends on what you do when using "-g"). The groups you add with "-G" are supplementary - they're needed to grant additional rights to a user. There's a default set of supplementary groups for new users to enable them to do basic task, e.g. printing or using media or storage devices.

M.
 
Old 05-13-2009, 03:32 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
@maxy7710: Minor correction:
Quote:
if no group name is mentioned while creating the user then default primary group is same as his username.
That depends on the distro that is used. Historically the group users is used, not the name of the user, although I know that Red Hat (and offspring?) use the username as groupname. Don't get me wrong, it is, from a safety point of view, a good thing.

Last edited by druuna; 05-13-2009 at 05:18 AM.
 
Old 05-13-2009, 12:40 PM   #6
saagar
Member
 
Registered: Jul 2008
Location: Chennai, India
Distribution: RHEL5, Ubuntu
Posts: 191

Rep: Reputation: 37
I have seen that in Solaris, when I create a user (with no primary group), by default he will be a member of a group called other (gid number 1).
 
Old 05-13-2009, 08:38 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Indeed, an unspecified primary group must default to something.
Historically it would have been 'users' (druuna) or maybe 'others' (saagar) or ...
RedHat decided sometime ago that for enhanced security it should default such that the group id was the same as the user id eg 1st user is usually 500:500, then 501:501 and so on.
RH derived systems tend to do the same. Other distros may also do this.
 
Old 05-14-2009, 01:37 PM   #8
MoonMind
Member
 
Registered: May 2005
Location: Switzerland
Distribution: Ubuntu
Posts: 448

Rep: Reputation: 38
Yep, I apologize for my over-generalisation - I'm used to Debian (based) systems, which default to "username usernameasgroupname", but I acknowledge that this is a questions of defaults or settings, repectively.

M.
 
  


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
shell script to find the difference betwwn two file and place the difference to other kittunot4u Linux - General 3 07-19-2010 05:26 AM
Difference in default path creating user with SMC and with useradd crisostomo_enrico Solaris / OpenSolaris 3 05-08-2007 08:32 AM
please tell me how to use useradd -b sabarigg Red Hat 2 06-08-2006 12:15 AM
Useradd - Cannot locate /etc/default/useradd in Solaris Paean Solaris / OpenSolaris 4 12-09-2005 02:36 AM
useradd cyrush Linux - Distributions 3 01-21-2003 10:40 PM


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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration