Where does "getent group A" get the information on group A? - linux

I have some questions about getent group.
Where does getent group A get the information on group A?
Does it only get it from /etc/group?
Is it possible that I can find a user (belonging to group A) by getent group A while I can not find the user from group A in /etc/group? If yes, how could this happen?
The third one is actually the problem I met.
Example:
1st. [root#*** test]# getent group A | grep A
2nd. [root#*** test]# cat $INSTALLROOT/etc/group | grep A
I can find a user a from the first command while I cannot find the user a from the second command.

Where does "getent group A" get the information on group A?
It is configured in /etc/nsswitch.conf. man getent tells this.
Does it only get from /etc/group?
It depends on your config files. On my machine it does not get this information only from /etc/group since it is configured in this way:
group: files ldap
is it possible that i can find a user (belong group A) by "getent group A" while can NOT find the user from group A in /etc/group?
Yes it is possible if there are at least two sources of data for groups.
By the way, take a look at how getent group work - run it under strace.
strace -s 256 -o getent.strace.txt -v getent group
And see what system calls it does. In my case it first reade from /etc/group and loads an ldap module and starts reading from socket

Related

Qsub: More than one host group

Is it possible to specify more than one host group in a call to qsub?
The specifications state that you can specify the host group with this syntax:
-q long.q##long.hgc (if long.hgc is a host group)
But I would like to know whether it is possible to specify more than one host group. There is nothing about that in the manual.
Just in case someone is curious about this, the answer was really straightforward:
-q long.q##long.hgc,long.q##long.hgd (if long.hgc and long.hgd are two host groups)

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

How to get Effective User Name and Schduling Class for a process using bash - linux

I'm trying to write a bash script that takes a process ID as the user input and prints out information about that process such as the nice value, priority...etc.
I almost got all what I need with help from this site: http://linux.die.net/man/5/proc
However, I couldn't find from where I can get the effective user name and the scheduling class of the process.
Any help would be appreciated.
The negated scheduling priority can be found as the 18th field of /proc/[pid]/stat as detailed in your link.
cat /proc/207/stat | cut -d' ' -f18
As for the owner of the process, it's the owner of the /proc/[pid] directory, or of any file in it.
stat -c "%U" /proc/207/
Edit : removed my scheduling priority calculation because I don't know the first thing about it and might misinterpret the documentation. I'll just leave where the negated one can be found.

linux command "getent" not returning all numeric usernames (ex. 10798) in linux file system

i am using "getent" command to fetch user information in my linux file system.
I have a user with the username "10798" and another user with the username "user" and user ID "10798",i am using getent command to fetch the user info of user with the name "10798"
but the command is not giving any output
I think the command "getent" will only look for the user id number if you give all numeric value as input to the command
here is the scenario
# cat /etc/passwd
10798:x:10799:10799::/home/10798:/bin/bash
user:x:10798:10798::/home/user:/bin/bash
# getent passwd 10798
user:x:10798:10798::/home/user:/bin/bash
how to get the user with the username 10798 using the getent command
passwd When no key is provided, use setpwent(3), getpwent(3),
and endpwent(3) to enumerate the passwd database. When
one or more key arguments are provided, pass each
numeric key to getpwuid(3) and each nonnumeric key to
getpwnam(3) and display the result.
I got this from the linux man page is there a way to redirect numeric keys to getpwnam
ls already performs that lookup. You can perform a user information lookup from the command line with getent passwd.
If ls shows a user ID instead of a user name, it's because there's no user by that name. Filesystems store user IDs, not user names. If you mount a filesystem from another system, or if a file belongs to a now-deleted user, or if you passed a numerical user ID to chown, you can have a file that belongs to a user ID that doesn't have a name.
On a shared host, you may have access to some files that are shared between several virtual machines, each with their user database. This is a bit weird (why share files but not the users that own them?), but it's technically possible.

why linux id command give me different info about the same account?

I am using ubuntu 13.04.
And I wonder why I get different groups info when using id command with/without account.
when I type
$id user1
uid=1000(user1) gid=1000(user1) groups=1000(user1),1001(user2)
but when I type
$id
uid=1000(user1) gid=1000(use1) groups=1000(user1),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare)
why use "id" command only cannot list my supplementary group?
by the way, following is one entry of my /etc/group :
user2:x:1001:user1
Any help ? Thank you.
Sounds like you've edited /etc/group but haven't logged off and back on again. I suggest starting a new shell, and trying id again.

Resources