You are not logged in.

#1 2010-09-15 13:34:19

Mr. Alex
Member
Registered: 2010-08-26
Posts: 623

Groups and their users - please explain

User "alex"

$ groups
disk wheel log network audio optical storage users

So it's in "users" group.

$ cat /etc/group | grep alex
disk:x:6:root,alex
wheel:x:10:root,alex
log:x:19:root,alex
network:x:90:alex
audio:x:92:alex
optical:x:93:hal,alex
storage:x:95:hal,alex

Alex is not in "users" here. Why? If I open "/etc/group", there will be:

...
users:x:100:
...

Offline

#2 2010-09-15 14:23:46

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Groups and their users - please explain

It's working fine here:

[karol@black ~]$ groups
tty disk wheel log locate http video audio optical floppy storage users
[karol@black ~]$ grep karol /etc/group
tty::5:karol
disk::6:root,karol
wheel::10:root,karol
log::19:root,karol
locate::21:karol
http::33:karol
video:x:91:root,karol
audio::92:root,karol
optical::93:karol,hal
floppy:x:94:karol,hal
storage:x:95:karol,hal
users::100:karol

Offline

#3 2010-09-15 14:34:51

rusty99
Member
Registered: 2009-03-18
Posts: 253

Re: Groups and their users - please explain

Mr. Alex wrote:
$ cat /etc/group | grep alex 

/OT - Much simpler

grep alex /etc/group

Offline

#4 2010-09-15 16:19:00

Bregol
Member
Registered: 2008-08-15
Posts: 175

Re: Groups and their users - please explain

if you look in /etc/passwd, you will see a couple numbers next to your user name - your user ID # and your default group ID #.  So your user is a member of whatever group # is in /etc/passwd in addition to wherever the user is listed in /etc/group.  So you get 1 group in /etc/passwd in addition to however many more groups you want to be in through /etc/group.  So in your case, it would appear that your /etc/passwd would list your default group as 100 (users).  You do not additionally need to list your username in /etc/group.  You can, but since it's in /etc/passwd, it doesn't really matter


Nai haryuvalyë melwa rë

Offline

#5 2010-09-16 14:43:54

Mr. Alex
Member
Registered: 2010-08-26
Posts: 623

Re: Groups and their users - please explain

So if "group ID" in /etc/passwd and /etc/group is the same, user is in this group automatically? No need to type his user name in /etc/group ?

Offline

#6 2010-09-16 18:04:31

Bregol
Member
Registered: 2008-08-15
Posts: 175

Re: Groups and their users - please explain

Right.  If /etc/passwd says "username:x:1000:100:......." that means username is user #1000 and is a part of group 100.  Note that only 1 group can be listed in /etc/passwd.  And yes they are automatically in that group.  Any additional groups may be given to the user by listing the user in /etc/group.

In the above example, there is no need to add "username" to group 100 in /etc/group, since it is stated in /etc/passwd that "username" belongs to group 100.  If you wanted to, you could also list "username" in group 100 in /etc/group, but that is not necessary.

The reason that /etc/passwd has you give a group to the username in /etc/passwd is so that for example if i were to make a new file, it would set the new file's ownership to my username and the group given to me in /etc/passwd.  In the above example, if i were to make a new file (with the user "username" as shown above with group #100 (users) in /etc/passwd), then the new file would by default belong to "username" and to group "users". 

So to answer your question simply: yes the user is automatically added to the group given in /etc/passwd.   And therefore there is no need to type the username in /etc/group.  You can if you want to, but there is no need to.  And one reason that there is a group listed in /etc/passwd rather than having it all done through /etc/group is so that when you make a file, it knows what group owns it by default.


Nai haryuvalyë melwa rë

Offline

Board footer

Powered by FluxBB