简体   繁体   中英

Inconsistency between “/etc/passwd” and “/etc/group”

Scenario 1:

I have 2 users, each has a different primary group. For user1, the primary group is group1 with GID 501. For user2, the primary group is group2 with GID 502.

I edited /etc/passwd so that user1 now has GID 600. However, I forgot to create a new group with GID 600 (and I did not edit /etc/group either).

What's surprising me is that even though I never created a group with GID 600 (and thus there's no such group in /etc/group )- everything works as if such a group exists:

Examples:

1) After user1 creates a new file- test.txt , User2 can't r/w that file.

2) When running ls -l I can see that test.txt belongs to GID 600.

What am I missing? Why does it work even though there's inconsistency between /etc/passwd and /etc/group ?


Scenario 2:

Say I have a group with GID 1000. When running useradd -c "name" test2 -g 1000 , and then groups test2 , I can see that test2 's primary group is 1000.

However, in /etc/group all I see is test_group:x:1000: , meaning test2 isn't a member of test_group .

Moreover, after running useradd -c "name" test3 , I do have test3:x:8093: in /etc/group .

Can you explain why it's happening?

Thanks.

Non programming question, expect downvotes... you should ask on superuser or unix.se

That said, there is no mapping of UID numbers to GID numbers that require them to have the same values. Think about what happens when you add a few users, then create a group or two for them to share, then add a few more users. The "next available" GID/UID pair don't match in value, but that doesn't matter.

When you are looking at a user's primary group, they aren't listed in the groups file as being a member because their primary group info is in the passwd file.

Remember to find files/directories that have no owning user or group if you manually change a UID number or GID number, and fix as appropriate.

Also, when it comes to UID numbers and GID numbers there is 0 (root) and everything else - no special meaning to them. By consensus, "system user" type accounts are low, and most distributions start creating "normal" users with a UID/GID of 1000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM