With Centos 6.6, when I run ps command, the first column is User ID and not user name.

root@cluster:mahmood# ps aux | grep Xvnc
506      11881  0.6  0.1 168580 63164 ?        S    Jun03  24:56 /usr/bin/Xvnc :6 -desktop cluster.hpc.org:6 (haghsheno) -auth /home/mahmood/.Xauthority -geometry 1000x900 -rfbwait 30000 -rfbauth /home/mahmood/.vnc/passwd -rfbport 5906 -fp catalogue:/etc/X11/fontpath.d -pn

Why such thing happens? and how can I change that to user name?

  • 2
    Is answerd hier why unix.stackexchange.com/questions/363910/…
    – user192526
    Jun 6, 2017 at 14:01
  • 1
    Does it show the numeric UID for processes of all users, or just some? Do getent passwd 506 and getent passwd $username work? (I think getent should lookup by number on CentOS)
    – ilkkachu
    Jun 6, 2017 at 14:19
  • It shows for some users. As pointed by Bahamut, it seems that the user name length is important!
    – mahmood
    Jun 6, 2017 at 14:21
  • or maybe you have a numeric username: unix.stackexchange.com/questions/287077/…
    – Jeff Schaller
    Jun 6, 2017 at 15:09

2 Answers 2


Unfortunately the default ps does not display a username if the username is longer than 8 chars. If your system is running sssd with LDAP you can use "getent passwd userid" to find the user if they are in the LDAP database or the password file. My username "tvb" almost always shows up. However the username "flonglastname" would not in most cases. Other commands like "w" will show the first 8 chars "flonglas" and truncate the remaining. In the example by @KevinO above, "haldaemon" is 9 chars so that's why it doesn't appear in ps as a username, but a userid instead.

% getent passwd haldaemon
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin

Also, the answer at blog.dbi-services.com helps with a way to specify the field length of the username field even in BSD format ps output. Simplifying their suggestion a little gives:

env PS_FORMAT='user:12,pid,%cpu,%mem,vsz,rss,tty,stat,start,time,command' ps ax | grep haldaemon
haldaemon     2032  0.0  0.0  53100  2020 ?        Ssl    Aug 12 00:01:10 hald

Which provides the desired output.


If the id is not inside passwd (grep 506 /etc/passwd) there is no username to display.

In this case add an corresponding entry inside /etc/passwd.

EDIT As mentioned by Jeff Schaller and KevinO:

This answer isn't quite complete! It's better to locate these lines from /etc/passwd, whose third field ($3, separated by colon -F:) contains exactly the value of 506. See first comment from Jeff. My simple example above would show lines containing username yx506, id 123506, and so on.

But anyway: if the userid is missing inside /etc/passwd, this answer could be a solution.

I'll try to be more concrete in future ...

  • or awk -F: '$3 == 506' /etc/passwd or getent passwd | awk -F: '$3 == 506'
    – Jeff Schaller
    Jun 6, 2017 at 15:08
  • Yes, my example could result in more than just one line. Wanted to keep it simple ... ;) Thanks anyway!
    – ChristophS
    Jun 6, 2017 at 15:12
  • This answer isn't quite complete, as an entry may be in /etc/passwd but still not display the textual user name. As an example, I have from ps -ef a line of :68 1964 1 0 May17 ? 00:00:30 hald (so it is showing the numeric id; most other lines have "root" or "apache" showing), but grep 68 /etc/passwd gives haldaemon:x:68:68:HAL daemon:/:/sbin/nologin.
    – KevinO
    Jun 6, 2017 at 15:16
  • userid 1506, username tax506, gid 5061, etc etc etc
    – Jeff Schaller
    Jun 6, 2017 at 15:19
  • @Jeff/Kevin: I hope the edit is acceptable for you ...
    – ChristophS
    Jun 6, 2017 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.