Id command does not return correct username

On server1 the "id" command works fine and returns "myuser" user as was expected. Below are the details of the good server.

$ id -nu 501
myuser

$ cat /etc/system-release
Red Hat Enterprise Linux Server release 7.6 (Maipo)

$ uname -a
Linux server1 3.10.0-957.el7.x86_64 #1 SMP Thu Oct 4 20:48:51 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

$ id
uid=501(myuser) gid=501(was) groups=501(was),1005(coluser)

$ cat /etc/passwd | grep myuser
myuser:x:501:501::/home/myuser:/bin/bash

$ cat /etc/passwd | grep 501
myuser:x:501:501::/home/myuser:/bin/bash

However on server2 the command does not return myuser user as was expected. Below are the details of the problematic server.

$  id -nu 501
id: 501: No such user

$ cat /etc/system-release
Red Hat Enterprise Linux Server release 6.10 (Santiago)

$ uname -a
Linux server2 2.6.32-754.23.1.el6.x86_64 #1 SMP Tue Sep 17 09:46:55 EDT 2019 x86_64 x86_64 x86_64 GNU/Linux

$ id
uid=501(myuser) gid=501(staff) groups=501(staff),507(coluser)
 
$ cat /etc/passwd | grep myuser
myuser:x:501:501::/home/wlsadmin:/bin/bash

$ cat /etc/passwd | grep 501
myuser:x:501:501::/home/wlsadmin:/bin/bash
myadmin:x:502:501::/home/myadmin:/bin/bash

Can you please suggest how can I get id -nu 501 to display myuser user on problematic server2 ?

First thought: non-printing control characters in string.

[NOPARSE][/NOPARSE]

If so, how can i get the user id of a running process that works on all OS types ? Below is what i have been using so far:

Id -nu `cat \proc\pid\loginuid`

This is a difference in the OS version. The RHEL 7 (or variant) manual pages will have something phrased like

.....where RHEL 6 (or variant) does not. It is just not a valid input.

Kind regards,
Robin

Difficult to believe cat \proc\pid\loginuid would give any meaningful output (unless you're on a windows machine running some *nix emulator).

In which case what would be the best approach towards getting the username given the pid ?

You might have some success with the following:-

getent passwd $user_number

You might need to process the output further, but it's a start.

Does that help,
Robin

Will updating the "id utility" to the latest version on the old 6.1 linux help ?

No, the feature is only available from the version in 7 so there is not package for version 6 to deliver it.

Robin

When you don't even know how to write a correct path you shouldn't be allowed to have a shell login, save for the sandbox to learn. When you ask your systems administrator how to do it tell him to remove your other user accounts. You are probably endangering the continuous operation of your corporate network.

I built a command to access Id info - design goal was to provide a CSV table across many systems with user info from both Solaris n Windows!

The script is able to Create CSV file while run as root and then you can collect info by hostname across the University ‘ s platforms into a very large spreadsheet.

In doing so I noticed that getent will follow rules set for each host!
Naturally the various hosts might only need a passwd/group file, or it might also obey the wider rules which were setup by active directory servers!

This was the main problem!
Either you get a username from the passwd/group with no interference
OR you get it with Active directory plus the the system passed/group!

I found that different hosts had 3 processes at most handling your credentials. So I completed an initial draft n checked my data!

Darn! Bug! Dog gone it!

Some systems enabled 2 n others enabled 3 processes!

So I now had to work out different procedures (the answers depended up the commands required) automatically within my script per host!

So ... it is not easy in a script to have the script detect all the processes and or files which will provide the “CORRECT & COMPLETE”” information for a SECURITY sweep!

The idea is for you to check the documentation for each command you use to see if Active Directory
Plays a part!

In your case you may have a network user enabled n the same user MAY/MAYNOT be in the passwd/group files!

Helpfull