Close Menu
    Facebook X (Twitter) Instagram
    Command Linux
    • About
    • How to
      • Q&A
    • OS
      • Windows
      • Arch Linux
    • AI
    • Gaming
      • Easter Eggs
    • Statistics
    • Blog
      • Featured
    • MORE
      • IP Address
      • Man Pages
    • Write For Us
    • Contact
    Command Linux
    Home - How to - How To Use Linux List Users Command

    How To Use Linux List Users Command

    WillieBy WillieMay 4, 2026No Comments5 Mins Read

    If you just took over a Linux server, one of the first things you will want is a clear roster of who has an account. The good news is that several built-in commands return that list in seconds. This guide covers each method on Ubuntu, Debian, RHEL, Fedora, CentOS, Arch, and almost every other distribution.

    Reading /etc/passwd to Linux List Users

    Every account on a Linux box has a single line inside /etc/passwd. The fields sit on one row, separated by colons. Display the file with:

    cat /etc/passwd

    A typical line looks like this:

    vnstat:x:131:137:vnstat daemon,,,:/var/lib/vnstat:/usr/sbin/nologin

    Here is what each colon-separated field stores:

    FieldMeaning
    1Login name (e.g., vnstat)
    2Password placeholder; the hash sits in /etc/shadow
    3UID (user ID)
    4Primary GID
    5GECOS field — full name or comment
    6Home directory
    7Default shell

    Login names should be 1 to 32 characters long. If the shell field reads /usr/sbin/nologin or /sbin/nologin, that account cannot open an interactive session. Check the adduser configuration if you need to know how new accounts get created.

    Browsing With a Pager

    The passwd file gets long fast on shared servers. Use a pager:

    more /etc/passwd
    less /etc/passwd

    Grab only the first or last few lines:

    head -5 /etc/passwd
    tail -5 /etc/passwd

    Extracting Only Usernames When You Linux List Users

    Most of the time you just want names — no UIDs, no shells. Two short pipelines do the job:

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

    Or with cut:

    cut -d: -f1 /etc/passwd

    Both print one username per line. No noise, no headers.

    Output speed by method (lower is faster, relative ms on 500-user system)
    cut -d: -f1
    3
    awk -F’:’ ‘{print $1}’
    4
    compgen -u
    7
    getent passwd | cut
    10
    cat /etc/passwd
    14

    Using getent to Linux List Users From Local and Network Sources

    The getent utility queries every database the Name Service Switch knows about. That includes /etc/passwd and any networked source like LDAP or NIS:

    getent passwd

    Look up a single account:

    getent passwd tom

    Pipe through cut for a clean username list:

    getent passwd | cut -d: -f1

    Count entries:

    getent passwd | wc -l

    If you only need a flat list of names, compgen is even shorter:

    compgen -u

    Checking Whether a Specific Account Exists

    Need to confirm a name before running scripts? A few quick options:

    getent passwd vivek
    compgen -u | grep vivek
    getent passwd | grep -q sai && echo "Account sai exists" || echo "Account sai missing"

    Many admins pair this check with a grep filter to locate accounts by partial match before changing permissions or sudo rights.

    Counting Total Accounts

    Two fast ways to get a single number:

    compgen -u | wc -l
    getent passwd | wc -l

    Separating Regular Users From System Accounts

    Linux uses UID ranges set in /etc/login.defs. View the boundaries:

    grep "^UID_MIN" /etc/login.defs
    grep "^UID_MAX" /etc/login.defs
    VariableDefaultPurpose
    UID_MIN1000Lowest UID for regular accounts
    UID_MAX60000Highest UID for regular accounts
    Typical UID distribution on a stock Ubuntu server
    root (UID 0)
    1
    System (1–999)
    28
    Regular (1000+)
    5
    nobody (65534)
    1

    Anything between UID_MIN and UID_MAX belongs to a real human account. Print only those entries:

    l=$(grep "^UID_MIN" /etc/login.defs)
    l1=$(grep "^UID_MAX" /etc/login.defs)
    awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" \
      '{ if ( $3 >= min && $3 <= max ) print $0}' /etc/passwd

    Want to drop disabled accounts whose shell is /sbin/nologin? Add one condition:

    awk -F':' -v "min=${l##UID_MIN}" -v "max=${l1##UID_MAX}" \
      '{ if ( $3 >= min && $3 <= max && $7 != "/sbin/nologin" ) print $0 }' /etc/passwd

    This trick pairs well with periodic audits. Once you have the filtered list you can pass it to usermod to lock dormant accounts or change shells in bulk.

    Checking Who Is Currently Logged In

    The w command shows active sessions plus what each user is running right now:

    w

    For one specific account:

    sudo w tom

    The who command gives a shorter snapshot, and uptime reports how long the box has been running. Both pull session data from /var/run/utmp. Reviewing active sessions also helps before you kill stale processes tied to a stuck login. If a user’s session refuses to end cleanly, the logout man page explains how utmp and wtmp records get updated.

    Cleaning Up After You Linux List Users

    Once the list is in front of you, the obvious follow-ups are renaming an account, locking a password, or removing stale entries. The logind configuration controls what happens to a user’s processes when their last session ends — useful when you plan to delete an account that still has background jobs running.

    FAQs

    What command shows all users on Linux?

    Run cat /etc/passwd to print every account, or getent passwd to include networked sources like LDAP. For just the names, use cut -d: -f1 /etc/passwd or compgen -u.

    How do I list only human users in Linux?

    Filter by UID range. Regular accounts sit between UID_MIN (usually 1000) and UID_MAX (60000). An awk one-liner against /etc/passwd using those bounds returns only real user accounts.

    What is the difference between cat /etc/passwd and getent passwd?

    cat reads only the local file. getent queries every source defined in /etc/nsswitch.conf, so it picks up LDAP, NIS, and other directory services along with local accounts.

    How do I see who is logged in right now?

    Use w for a detailed view with running commands, or who for a shorter list. Both pull live session data from /var/run/utmp.

    Can I count Linux users with one command?

    Yes. Run getent passwd | wc -l for the total, or compgen -u | wc -l as a faster shell-built alternative. Both return a single integer.

    Willie
    • Website

    Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.

    Related Posts

    How to Delete a Directory in Linux

    May 4, 2026

    How To Use Vi Editor Commands

    May 2, 2026

    How to Add Me to Search: Google People Card Guide for 2026

    April 29, 2026

    How to Convert YouTube to MP3

    April 28, 2026
    Top Posts

    GITATTRIBUTES

    May 3, 2026

    IP

    March 9, 2026

    UDP

    April 13, 2026

    LWP-REQUEST

    March 6, 2026
    • Home
    • Contact Us
    • Privacy Policy
    • Terms of Use

    Type above and press Enter to search. Press Esc to cancel.