LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-27-2006, 09:45 AM   #1
essdeeay
Member
 
Registered: Aug 2004
Location: United Kingdom
Distribution: Debian
Posts: 88

Rep: Reputation: 15
Question Help needed with 'useradd'


From reading the man pages, the -g option in useradd is meant to set
Quote:
The group name or number of the user's initial login group. The group name must exist.
Simple test to begin with, and as expected, User bill is created along with Group bill
Code:
useradd -m bill
I want bill to have Group users as his primary group. On my system, the group users already exists, so I tried this command
Code:
useradd -g users -m bill
User bill is created, but /etc/group does not list bill in the users group, it also does not show Group bill.
The only way I could create bill with a primary login group of users was to use this command
Code:
useradd -G users -g users -m bill
My question is, I don't understand why I have to write the command like this.

Any ideas?

Thanks,
Steve
 
Old 03-27-2006, 09:47 AM   #2
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 76
I don't see any reason why your command failed.
Code:
#useradd -g users -G other,comma,seperated,groups -m bill
The above should also work. If the primary group is already "users" there is no need to list "users" in other groups.

The group bill is not created because by stipulating the default group as users, you overode the default behaviour in most Redhat based distros. If you want a group with the same name as the user to be created, you have to do
Code:
#useradd -m bill

Last edited by reddazz; 03-27-2006 at 09:58 AM.
 
Old 03-27-2006, 09:52 AM   #3
essdeeay
Member
 
Registered: Aug 2004
Location: United Kingdom
Distribution: Debian
Posts: 88

Original Poster
Rep: Reputation: 15
Thanks for the quick reply redazz. But...

Why do I *need* to specify -G in addition to -g when I just want to make bill and make his primary group users?

Thanks,
Steve
 
Old 03-27-2006, 10:19 AM   #4
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 76
Quote:
Originally Posted by essdeeay
Thanks for the quick reply redazz. But...

Why do I *need* to specify -G in addition to -g when I just want to make bill and make his primary group users?

Thanks,
Steve
As far as I know -G is optional so you should be able to create a new user without it. I have just tried to reproduce your problem on Gentoo, CentOS and Suse, but I can't.
Code:
#useradd -g somegroup -m user
This works fine without stipulating any extra groups.
 
Old 03-27-2006, 10:22 AM   #5
essdeeay
Member
 
Registered: Aug 2004
Location: United Kingdom
Distribution: Debian
Posts: 88

Original Poster
Rep: Reputation: 15
Hmm... I should have tested more first... I was looking at /etc/group to check group membership.

You are correct, it does actually work (I tested by su'ing), but how can you list group membership if /etc/group isn't giving you the correct info?

Thanks,
Steve
 
Old 03-27-2006, 01:56 PM   #6
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 76
To check group membership do
Code:
#groups username
 
Old 03-27-2006, 03:01 PM   #7
essdeeay
Member
 
Registered: Aug 2004
Location: United Kingdom
Distribution: Debian
Posts: 88

Original Poster
Rep: Reputation: 15
Thumbs up

Thank you very much reddazz.

Steve
 
Old 03-28-2006, 01:29 AM   #8
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Quote:
if /etc/group isn't giving you the correct info?
Just a hint: the "default" or "primary" group is stored in /etc/passwd, not /etc/group.
If the user is member of any other groups (besides the default), his username appears in the corresponding
lines of /etc/group.

See also:
Code:
man id
The "newgrp" can change your (primary) group while you're logged in, so that any new files/dirs you create get a different group by default.
 
Old 03-28-2006, 04:35 AM   #9
essdeeay
Member
 
Registered: Aug 2004
Location: United Kingdom
Distribution: Debian
Posts: 88

Original Poster
Rep: Reputation: 15
Thumbs up

Thank you, your "just a hint" hit the nail on the head - perfect!

Steve
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Useradd - Cannot locate /etc/default/useradd in Solaris Paean Solaris / OpenSolaris 4 12-09-2005 01:36 AM
useradd jerryluis Fedora 9 03-27-2005 07:37 PM
useradd cyrush Linux - Distributions 3 01-21-2003 09:40 PM
useradd command needed from shelll promp tarak4u Linux - Networking 1 07-31-2002 05:09 PM
useradd qdickens Linux - General 4 11-02-2001 02:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:32 AM.

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
Open Source Consulting | Domain Registration