Linux: How to List All Users and Groups

This post will guide you how to list all users and groups in your current Linux system. How do I show all user account in Ubuntu/CentOS Linux. How to search for a given user name in Linux.

List All Users


If you want to List all users in your Linux system, you can cat the content of /etc/passwd file, and it will contain a list of the system’s accounts and other useful information, such as: User ID, Group ID, Home directory.etc. type the following commmand to list all user accounts and its useful information:

# cat /etc/passwd

Or

# less /etc/passwd

Outputs:

devops@devops-osetc:~/working$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false
syslog:x:104:108::/home/syslog:/bin/false
_apt:x:105:65534::/nonexistent:/bin/false
messagebus:x:106:110::/var/run/dbus:/bin/false
uuidd:x:107:111::/run/uuidd:/bin/false
lightdm:x:108:114:Light Display Manager:/var/lib/lightdm:/bin/false
whoopsie:x:109:116::/nonexistent:/bin/false
avahi-autoipd:x:110:119:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/bin/false
avahi:x:111:120:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
dnsmasq:x:112:65534:dnsmasq,,,:/var/lib/misc:/bin/false
colord:x:113:123:colord colour management daemon,,,:/var/lib/colord:/bin/false
speech-dispatcher:x:114:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false
hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false
kernoops:x:116:65534:Kernel Oops Tracking Daemon,,,:/:/bin/false
pulse:x:117:124:PulseAudio daemon,,,:/var/run/pulse:/bin/false
rtkit:x:118:126:RealtimeKit,,,:/proc:/bin/false
saned:x:119:127::/var/lib/saned:/bin/false
usbmux:x:120:46:usbmux daemon,,,:/var/lib/usbmux:/bin/false
devops:x:1000:1000:devops,,,:/home/devops:/bin/bash
sshd:x:121:65534::/var/run/sshd:/usr/sbin/nologin
mysql:x:122:129:MySQL Server,,,:/nonexistent:/bin/false
redis:x:123:130::/var/lib/redis:/bin/false

If you only want to list user names for user list, you can use the cut command or awk command to only print the first field, type:

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

Outputs:

devops@devops-osetc:~/working$ awk -F ':' '{ print $1}' /etc/passwd
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
......

If you want to check if one given user name exists in your system, you can use the grep command to check, type:

# grep '^root' /etc/passwd | awk -F ':' '{ print $1}'

Outputs:

devops@devops-osetc:~/working$ grep '^root' /etc/passwd | awk -F ':' '{ print $1}'
root

List All Groups


If you want to list all groups in your Linux system, you can use cat command to print all lists in /etc/group file. This file will contain all group names and its ID information. Type the following command:

# cat /etc/group

Or

# less /etc/group

Outputs:

devops@devops-osetc:~/working$ cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog,devops
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
......

Show Which Linux Users are logged in


If you want to check who is logged on your Linux system, you can execute Who command, type:

# who

outputs:

devops@devops-osetc:~/working$ who
devops tty7 2018-12-18 21:27 (:0)
devops pts/1 2018-12-18 21:28 (10.182.37.163)

 

You might also like:

Sidebar



back to top