LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Help needed with 'useradd' (https://www.linuxquestions.org/questions/linux-general-1/help-needed-with-useradd-428987/)

essdeeay 03-27-2006 09:45 AM

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 :)

reddazz 03-27-2006 09:47 AM

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

essdeeay 03-27-2006 09:52 AM

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 :)

reddazz 03-27-2006 10:19 AM

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.

essdeeay 03-27-2006 10:22 AM

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 :)

reddazz 03-27-2006 01:56 PM

To check group membership do
Code:

#groups username

essdeeay 03-27-2006 03:01 PM

Thank you very much reddazz.

Steve :)

timmeke 03-28-2006 01:29 AM

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.

essdeeay 03-28-2006 04:35 AM

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

Steve :)


All times are GMT -5. The time now is 08:39 PM.