What is the command that allows one to generate a list of all the usernames of authorised users on a Linux server? I have tried

  1. getent passwd | cut -d : -f 1 | xargs groups


  1. less /etc/passwd


  1. grep 'x:0:' /etc/passwd and

  2. getent passwd


  1. grep "/bin/bash" /etc/passwd | cut -d: -f1

but none of the above gives me exactly what I want, which is simply a list of usernames.

Any help would be greatly appreciated

migrated from serverfault.com Oct 2 '14 at 7:55

This question came from our site for system and network administrators.


Use your first attempt, but remove the | xargs groups. Really, though, this is basic enough that it's not all that appropriate for this site...


awk(1) is another useful tool. awk is able to parse individual fields from lines of text, based on a specified delimiter. In the case of /etc/passwd, that delimiter is a colon, hence we pass '-F:' on the awk command line. Likewise, since the user name is the first field of the line, and awk numbers fields beginning at 1, we stipulate 'print $1' to tell awk to print the first field of each line.

awk -F: '{ print $1 }' < /etc/passwd

This can easily be adapted to print any field from the passwd file. Here is a list of each user's name (field 1), followed by a space, followed by their login shell (field 7):

awk -F: '{ print $1, $7 }' < /etc/passwd

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.