Listing all accounts on an Ubuntu Linux system

Learning that lasts. Online courses from $14.99
If you need to list all of the accounts on an Ubuntu Linux system, there are many commands that you can use.
  1. You can view the contents of the /etc/passwd with the cat command, i.e.:

    cat /etc/passwd

  2. If you just want to see the account names and not other information for the accounts, such as the user and group ids, login shells, etc., you can use the grep command using:

    grep -oE '^[^:]+' /etc/passwd.

    Explanation

  3. Alternatively, you can examine the file with the cut command looking at only the first field in the file (the fields are separated by colons):

    cut -d: -f1 /etc/passwd

  4. Another alternative is to use an awk command:

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

    To filter for human users (usually UIDs 1000) rather than system accounts, use:

    awk -F: '$3 >= 1000 && $3 != 65534 {print $1}' /etc/passwd

  5. You can also use the lslogins command:

    joe@Lotus:~$ lslogins
      UID USER                 PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
        0 root                  240        0        0            root
        1 daemon                  0                              daemon
        2 bin                     0                              bin
        3 sys                     0                              sys
        4 sync                    0                              sync
        5 games                   0                              games
        6 man                     0                              man
        7 lp                      0                              lp
        8 mail                    0                              mail
        9 news                    0                              news
       10 uucp                    0                              uucp
       13 proxy                   0                              proxy
       33 www-data                0                              www-data
       34 backup                  0                              backup
       38 list                    0                              Mailing List Manage
       39 irc                     0                              ircd
       42 _apt                    0                              
      100 dhcpcd                  0                              DHCP Client Daemon
      101 syslog                  1                              
      102 _chrony                 2                              Chrony daemon
      103 tss                     0                              TPM software stack
      104 uuidd                   0                              
      105 whoopsie                0                              
      106 avahi                   2                              Avahi mDNS daemon
      107 nm-openvpn              0                              NetworkManager Open
      108 tcpdump                 0                              
      109 sssd                    0                              SSSD system user
      110 speech-dispatcher       0                              Speech Dispatcher
      111 usbmux                  0                              usbmux daemon
      112 cups-pk-helper          0                              user for cups-pk-he
      113 saned                   0                              
      114 geoclue                 0                              
      115 cups-browsed            1                              
      116 hplip                   0                              HPLIP system user
      117 rtkit                   1                              RealtimeKit
      118 colord                  1                              colord colour manag
      119 gnome-initial-setup     0                              
      984 gdm                     0                              Gnome Display Manag
      985 polkitd                 1                              User for polkitd
      986 gnome-remote-desktop    0                              GNOME Remote Deskto
      987 pipewire                0                              system user for pip
      988 fwupd-refresh           0                              Firmware update dae
      989 systemd-oom             1                              systemd Userspace O
      990 systemd-resolve         1                              systemd Resolver
      996 messagebus              1                              System Message Bus
      998 systemd-network         0                              systemd Network Man
      999 dnsmasq                 0                              dnsmasq
     1000 joe                   103                        19:20 Joe
    65534 nobody                  0        0        0            nobody
    joe@Lotus:~$
  6. Or you could use the compgen command compgen -u:

    joe@Lotus:~$ compgen -u
    root
    daemon
    bin
    sys
    sync
    games
    man
    lp
    mail
    news
    uucp
    proxy
    www-data
    backup
    list
    irc
    _apt
    nobody
    systemd-network
    dhcpcd
    messagebus
    syslog
    systemd-resolve
    _chrony
    tss
    uuidd
    systemd-oom
    whoopsie
    dnsmasq
    avahi
    nm-openvpn
    tcpdump
    sssd
    speech-dispatcher
    usbmux
    cups-pk-helper
    fwupd-refresh
    saned
    geoclue
    cups-browsed
    pipewire
    hplip
    gnome-remote-desktop
    polkitd
    rtkit
    colord
    gnome-initial-setup
    gdm
    joe
    joe@Lotus:~$
  7. You could also use the getent command, which will show all user accounts, regardless of the type of name service used, so it will show all local and Light Directory Access Protocol (LDAP) users.

    joe@Lotus:~$ getent 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:/run/ircd:/usr/sbin/nologin
    _apt:x:42:65534::/nonexistent:/usr/sbin/nologin
    nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
    systemd-network:x:998:998:systemd Network Management:/:/usr/sbin/nologin
    dhcpcd:x:100:65534:DHCP Client Daemon:/usr/lib/dhcpcd:/bin/false
    messagebus:x:996:996:System Message Bus:/nonexistent:/usr/sbin/nologin
    syslog:x:101:101::/nonexistent:/usr/sbin/nologin
    systemd-resolve:x:990:990:systemd Resolver:/:/usr/sbin/nologin
    _chrony:x:102:102:Chrony daemon:/var/lib/chrony:/usr/sbin/nologin
    tss:x:103:105:TPM software stack:/var/lib/tpm:/bin/false
    uuidd:x:104:107::/run/uuidd:/usr/sbin/nologin
    systemd-oom:x:989:989:systemd Userspace OOM Killer:/:/usr/sbin/nologin
    whoopsie:x:105:110::/nonexistent:/bin/false
    dnsmasq:x:999:65534:dnsmasq:/var/lib/misc:/usr/sbin/nologin
    avahi:x:106:112:Avahi mDNS daemon:/run/avahi-daemon:/usr/sbin/nologin
    nm-openvpn:x:107:113:NetworkManager OpenVPN:/var/lib/openvpn/chroot:/usr/sbin/nologin
    tcpdump:x:108:114::/nonexistent:/usr/sbin/nologin
    sssd:x:109:115:SSSD system user:/var/lib/sss:/usr/sbin/nologin
    speech-dispatcher:x:110:29:Speech Dispatcher:/run/speech-dispatcher:/bin/false
    usbmux:x:111:46:usbmux daemon:/var/lib/usbmux:/usr/sbin/nologin
    cups-pk-helper:x:112:116:user for cups-pk-helper service:/nonexistent:/usr/sbin/nologin
    fwupd-refresh:x:988:988:Firmware update daemon:/var/lib/fwupd:/usr/sbin/nologin
    saned:x:113:117::/var/lib/saned:/usr/sbin/nologin
    geoclue:x:114:118::/var/lib/geoclue:/usr/sbin/nologin
    cups-browsed:x:115:116::/nonexistent:/usr/sbin/nologin
    pipewire:x:987:987:system user for pipewire:/nonexistent:/usr/sbin/nologin
    hplip:x:116:7:HPLIP system user:/run/hplip:/bin/false
    gnome-remote-desktop:x:986:986:GNOME Remote Desktop:/var/lib/gnome-remote-desktop:/usr/sbin/nologin
    polkitd:x:985:985:User for polkitd:/:/usr/sbin/nologin
    rtkit:x:117:119:RealtimeKit:/proc:/usr/sbin/nologin
    colord:x:118:120:colord colour management daemon:/var/lib/colord:/usr/sbin/nologin
    gnome-initial-setup:x:119:65534::/run/gnome-initial-setup/:/bin/false
    gdm:x:984:984:Gnome Display Manager:/var/lib/gdm3:/bin/false
    joe:x:1000:1000:Joe:/home/joe:/bin/bash
    joe@Lotus:~$