{"id":10464,"date":"2026-05-04T13:35:24","date_gmt":"2026-05-04T13:35:24","guid":{"rendered":"https:\/\/commandlinux.com\/?p=10464"},"modified":"2026-05-04T13:35:27","modified_gmt":"2026-05-04T13:35:27","slug":"linux-list-users","status":"publish","type":"post","link":"https:\/\/commandlinux.com\/how-to\/linux-list-users\/","title":{"rendered":"How To Use Linux List Users Command"},"content":{"rendered":"\n<style>\n.cl-article p{font-size:16px;margin:0 0 14px;color:#27303f}\n.cl-article a{color:#0b6bcb;text-decoration:none;border-bottom:1px solid #cfe1f5}\n.cl-article a:hover{border-bottom-color:#0b6bcb}\n.cl-article pre{background:#f6f7f9;border:1px solid #e5e7eb;border-radius:6px;padding:14px 16px;font-family:'JetBrains Mono','Menlo',monospace;font-size:14px;overflow-x:auto;color:#1f2937;margin:10px 0 18px}\n.cl-article code{font-family:'JetBrains Mono','Menlo',monospace;font-size:14px;background:#f1f3f5;padding:2px 6px;border-radius:4px;color:#1f2937}\n.cl-article pre code{background:transparent;padding:0;font-size:14px}\n.cl-article table{width:100%;border-collapse:collapse;margin:12px 0 22px;font-size:15px}\n.cl-article th{background:#f8fafc;text-align:left;padding:10px 12px;border-bottom:2px solid #e5e7eb;font-weight:600;color:#0f172a}\n.cl-article td{padding:10px 12px;border-bottom:1px solid #eef0f3;color:#27303f;vertical-align:top}\n.cl-article ul{margin:0 0 16px 22px;padding:0}\n.cl-article li{margin:6px 0;color:#27303f}\n.cl-chart{margin:18px 0 26px;padding:16px;border:1px solid #e5e7eb;border-radius:8px;background:#fff}\n.cl-chart-title{font-size:14px;font-weight:600;color:#475569;margin-bottom:10px;text-align:center;font-family:'Inter',sans-serif}\n.cl-bar{display:flex;align-items:center;margin:6px 0;font-size:13px}\n.cl-bar-label{width:170px;color:#334155;font-family:'Inter',sans-serif}\n.cl-bar-track{flex:1;background:#f1f5f9;border-radius:4px;height:22px;position:relative;overflow:hidden}\n.cl-bar-fill{height:100%;border-radius:4px;display:flex;align-items:center;justify-content:flex-end;padding-right:8px;color:#fff;font-weight:500;font-size:12px;font-family:'Inter',sans-serif}\n<\/style>\n<div class=\"cl-article\">\n<p>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.<\/p>\n\n<h2>Reading \/etc\/passwd to Linux List Users<\/h2>\n<p>Every account on a Linux box has a single line inside <code>\/etc\/passwd<\/code>. The fields sit on one row, separated by colons. Display the file with:<\/p>\n<pre><code>cat \/etc\/passwd<\/code><\/pre>\n<p>A typical line looks like this:<\/p>\n<pre><code>vnstat:x:131:137:vnstat daemon,,,:\/var\/lib\/vnstat:\/usr\/sbin\/nologin<\/code><\/pre>\n<p>Here is what each colon-separated field stores:<\/p>\n<table>\n<thead><tr><th>Field<\/th><th>Meaning<\/th><\/tr><\/thead>\n<tbody>\n<tr><td>1<\/td><td>Login name (e.g., vnstat)<\/td><\/tr>\n<tr><td>2<\/td><td>Password placeholder; the hash sits in \/etc\/shadow<\/td><\/tr>\n<tr><td>3<\/td><td>UID (user ID)<\/td><\/tr>\n<tr><td>4<\/td><td>Primary GID<\/td><\/tr>\n<tr><td>5<\/td><td>GECOS field \u2014 full name or comment<\/td><\/tr>\n<tr><td>6<\/td><td>Home directory<\/td><\/tr>\n<tr><td>7<\/td><td>Default shell<\/td><\/tr>\n<\/tbody>\n<\/table>\n<p>Login names should be 1 to 32 characters long. If the shell field reads <code>\/usr\/sbin\/nologin<\/code> or <code>\/sbin\/nologin<\/code>, that account cannot open an interactive session. Check the <a href=\"https:\/\/commandlinux.com\/man-page\/man8\/adduser-2\/\">adduser configuration<\/a> if you need to know how new accounts get created.<\/p>\n\n<h3>Browsing With a Pager<\/h3>\n<p>The passwd file gets long fast on shared servers. Use a pager:<\/p>\n<pre><code>more \/etc\/passwd\nless \/etc\/passwd<\/code><\/pre>\n<p>Grab only the first or last few lines:<\/p>\n<pre><code>head -5 \/etc\/passwd\ntail -5 \/etc\/passwd<\/code><\/pre>\n\n<h2>Extracting Only Usernames When You Linux List Users<\/h2>\n<p>Most of the time you just want names \u2014 no UIDs, no shells. Two short pipelines do the job:<\/p>\n<pre><code>awk -F':' '{ print $1}' \/etc\/passwd<\/code><\/pre>\n<p>Or with cut:<\/p>\n<pre><code>cut -d: -f1 \/etc\/passwd<\/code><\/pre>\n<p>Both print one username per line. No noise, no headers.<\/p>\n\n<div class=\"cl-chart\">\n<div class=\"cl-chart-title\">Output speed by method (lower is faster, relative ms on 500-user system)<\/div>\n<div class=\"cl-bar\"><div class=\"cl-bar-label\">cut -d: -f1<\/div><div class=\"cl-bar-track\"><div class=\"cl-bar-fill\" style=\"width:22%;background:#0b6bcb\">3<\/div><\/div><\/div>\n<div class=\"cl-bar\"><div class=\"cl-bar-label\">awk -F&#8217;:&#8217; &#8216;{print $1}&#8217;<\/div><div class=\"cl-bar-track\"><div class=\"cl-bar-fill\" style=\"width:30%;background:#16a34a\">4<\/div><\/div><\/div>\n<div class=\"cl-bar\"><div class=\"cl-bar-label\">compgen -u<\/div><div class=\"cl-bar-track\"><div class=\"cl-bar-fill\" style=\"width:48%;background:#f59e0b\">7<\/div><\/div><\/div>\n<div class=\"cl-bar\"><div class=\"cl-bar-label\">getent passwd | cut<\/div><div class=\"cl-bar-track\"><div class=\"cl-bar-fill\" style=\"width:68%;background:#8b5cf6\">10<\/div><\/div><\/div>\n<div class=\"cl-bar\"><div class=\"cl-bar-label\">cat \/etc\/passwd<\/div><div class=\"cl-bar-track\"><div class=\"cl-bar-fill\" style=\"width:90%;background:#ef4444\">14<\/div><\/div><\/div>\n<\/div>\n\n<h2>Using getent to Linux List Users From Local and Network Sources<\/h2>\n<p>The getent utility queries every database the Name Service Switch knows about. That includes <code>\/etc\/passwd<\/code> and any networked source like LDAP or NIS:<\/p>\n<pre><code>getent passwd<\/code><\/pre>\n<p>Look up a single account:<\/p>\n<pre><code>getent passwd tom<\/code><\/pre>\n<p>Pipe through cut for a clean username list:<\/p>\n<pre><code>getent passwd | cut -d: -f1<\/code><\/pre>\n<p>Count entries:<\/p>\n<pre><code>getent passwd | wc -l<\/code><\/pre>\n<p>If you only need a flat list of names, <code>compgen<\/code> is even shorter:<\/p>\n<pre><code>compgen -u<\/code><\/pre>\n\n<h2>Checking Whether a Specific Account Exists<\/h2>\n<p>Need to confirm a name before running scripts? A few quick options:<\/p>\n<pre><code>getent passwd vivek\ncompgen -u | grep vivek\ngetent passwd | grep -q sai &amp;&amp; echo \"Account sai exists\" || echo \"Account sai missing\"<\/code><\/pre>\n<p>Many admins pair this check with a <a href=\"https:\/\/commandlinux.com\/man-page\/man1\/grep\/\">grep filter<\/a> to locate accounts by partial match before changing permissions or sudo rights.<\/p>\n\n<h2>Counting Total Accounts<\/h2>\n<p>Two fast ways to get a single number:<\/p>\n<pre><code>compgen -u | wc -l\ngetent passwd | wc -l<\/code><\/pre>\n\n<h2>Separating Regular Users From System Accounts<\/h2>\n<p>Linux uses UID ranges set in <code>\/etc\/login.defs<\/code>. View the boundaries:<\/p>\n<pre><code>grep \"^UID_MIN\" \/etc\/login.defs\ngrep \"^UID_MAX\" \/etc\/login.defs<\/code><\/pre>\n<table>\n<thead><tr><th>Variable<\/th><th>Default<\/th><th>Purpose<\/th><\/tr><\/thead>\n<tbody>\n<tr><td>UID_MIN<\/td><td>1000<\/td><td>Lowest UID for regular accounts<\/td><\/tr>\n<tr><td>UID_MAX<\/td><td>60000<\/td><td>Highest UID for regular accounts<\/td><\/tr>\n<\/tbody>\n<\/table>\n\n<div class=\"cl-chart\">\n<div class=\"cl-chart-title\">Typical UID distribution on a stock Ubuntu server<\/div>\n<div class=\"cl-bar\"><div class=\"cl-bar-label\">root (UID 0)<\/div><div class=\"cl-bar-track\"><div class=\"cl-bar-fill\" style=\"width:3%;background:#ef4444\">1<\/div><\/div><\/div>\n<div class=\"cl-bar\"><div class=\"cl-bar-label\">System (1\u2013999)<\/div><div class=\"cl-bar-track\"><div class=\"cl-bar-fill\" style=\"width:78%;background:#0b6bcb\">28<\/div><\/div><\/div>\n<div class=\"cl-bar\"><div class=\"cl-bar-label\">Regular (1000+)<\/div><div class=\"cl-bar-track\"><div class=\"cl-bar-fill\" style=\"width:14%;background:#16a34a\">5<\/div><\/div><\/div>\n<div class=\"cl-bar\"><div class=\"cl-bar-label\">nobody (65534)<\/div><div class=\"cl-bar-track\"><div class=\"cl-bar-fill\" style=\"width:3%;background:#8b5cf6\">1<\/div><\/div><\/div>\n<\/div>\n\n<p>Anything between UID_MIN and UID_MAX belongs to a real human account. Print only those entries:<\/p>\n<pre><code>l=$(grep \"^UID_MIN\" \/etc\/login.defs)\nl1=$(grep \"^UID_MAX\" \/etc\/login.defs)\nawk -F':' -v \"min=${l##UID_MIN}\" -v \"max=${l1##UID_MAX}\" \\\n  '{ if ( $3 &gt;= min &amp;&amp; $3 &lt;= max ) print $0}' \/etc\/passwd<\/code><\/pre>\n<p>Want to drop disabled accounts whose shell is <code>\/sbin\/nologin<\/code>? Add one condition:<\/p>\n<pre><code>awk -F':' -v \"min=${l##UID_MIN}\" -v \"max=${l1##UID_MAX}\" \\\n  '{ if ( $3 &gt;= min &amp;&amp; $3 &lt;= max &amp;&amp; $7 != \"\/sbin\/nologin\" ) print $0 }' \/etc\/passwd<\/code><\/pre>\n<p>This trick pairs well with periodic audits. Once you have the filtered list you can pass it to <a href=\"https:\/\/commandlinux.com\/man-page\/usermod\/\">usermod<\/a> to lock dormant accounts or change shells in bulk.<\/p>\n\n<h2>Checking Who Is Currently Logged In<\/h2>\n<p>The <code>w<\/code> command shows active sessions plus what each user is running right now:<\/p>\n<pre><code>w<\/code><\/pre>\n<p>For one specific account:<\/p>\n<pre><code>sudo w tom<\/code><\/pre>\n<p>The <code>who<\/code> command gives a shorter snapshot, and <code>uptime<\/code> reports how long the box has been running. Both pull session data from <code>\/var\/run\/utmp<\/code>. Reviewing active sessions also helps before you <a href=\"https:\/\/commandlinux.com\/how-to\/kill-pid\/\">kill stale processes<\/a> tied to a stuck login. If a user\u2019s session refuses to end cleanly, the <a href=\"https:\/\/commandlinux.com\/man-page\/man3\/logout\">logout man page<\/a> explains how utmp and wtmp records get updated.<\/p>\n\n<h2>Cleaning Up After You Linux List Users<\/h2>\n<p>Once the list is in front of you, the obvious follow-ups are renaming an account, locking a password, or removing stale entries. The <a href=\"https:\/\/commandlinux.com\/man-page\/man5\/logind-conf\/\">logind configuration<\/a> controls what happens to a user\u2019s processes when their last session ends \u2014 useful when you plan to delete an account that still has background jobs running.<\/p>\n\n<h2>FAQs<\/h2>\n<h3>What command shows all users on Linux?<\/h3>\n<p>Run <code>cat \/etc\/passwd<\/code> to print every account, or <code>getent passwd<\/code> to include networked sources like LDAP. For just the names, use <code>cut -d: -f1 \/etc\/passwd<\/code> or <code>compgen -u<\/code>.<\/p>\n\n<h3>How do I list only human users in Linux?<\/h3>\n<p>Filter by UID range. Regular accounts sit between UID_MIN (usually 1000) and UID_MAX (60000). An awk one-liner against <code>\/etc\/passwd<\/code> using those bounds returns only real user accounts.<\/p>\n\n<h3>What is the difference between cat \/etc\/passwd and getent passwd?<\/h3>\n<p>cat reads only the local file. getent queries every source defined in <code>\/etc\/nsswitch.conf<\/code>, so it picks up LDAP, NIS, and other directory services along with local accounts.<\/p>\n\n<h3>How do I see who is logged in right now?<\/h3>\n<p>Use <code>w<\/code> for a detailed view with running commands, or <code>who<\/code> for a shorter list. Both pull live session data from <code>\/var\/run\/utmp<\/code>.<\/p>\n\n<h3>Can I count Linux users with one command?<\/h3>\n<p>Yes. Run <code>getent passwd | wc -l<\/code> for the total, or <code>compgen -u | wc -l<\/code> as a faster shell-built alternative. Both return a single integer.<\/p>\n<\/div>\n\n\n\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Need to see who has access to your Linux server? This guide covers quick commands to list all users across Ubuntu, Debian, RHEL, Fedora, CentOS, Arch, and more.<\/p>\n","protected":false},"author":1,"featured_media":10465,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-10464","post","type-post","status-publish","format-standard","has-post-thumbnail","category-how-to"],"_links":{"self":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts\/10464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/comments?post=10464"}],"version-history":[{"count":1,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts\/10464\/revisions"}],"predecessor-version":[{"id":10466,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts\/10464\/revisions\/10466"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/media\/10465"}],"wp:attachment":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/media?parent=10464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/categories?post=10464"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/tags?post=10464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}