As a Linux System Administrator, you will often need to list all users on your Linux server. Here you will find various Linux commands to list all users on the Linux operating system, including Ubuntu, Debian, RHEL, Arch, Fedora, CentOS, and other distros.
You can use one of the following commands:
$ cat /etc/passwd $ more /etc/passwd $ less /etc/passwd
Sample output:
root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt ... postfix:x:89:89::/var/spool/postfix:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin vboxadd:x:988:1::/var/run/vboxadd:/bin/false apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
Sample line extracted from the output:
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
Notes:
apache | the user name (login name). |
x | This signifies that encrypted password is stored in the /etc/shadow file. |
48 | UID (user ID number). |
48 | Primary GID (group ID number). This number might be different from the previous one, depending on the user. |
Apache | GECOS. It may includes user’s full name (or application name, if the account is for a program), building and room number or contact person, office telephone number, home telephone number and any other contact information. |
/usr/share/ | Home directory for the user. |
/sbin/nologin | Login shell for the user. |
You can also use pagers such as more/less/most
commands as follows to view the /etc/passwd
file:
$ more /etc/passwd $ less /etc/passwd $ most /etc/passwd
If you want, you can limit your output lines using head
or tail
commands:
tail -5 /etc/passwd head -5 /etc/passwd
If you want to learn more, read also the second part of this tutorial.