{"id":13497,"date":"2025-08-29T14:40:38","date_gmt":"2025-08-29T14:40:38","guid":{"rendered":"https:\/\/hostnoc-revamp.branex.org\/blog\/?p=13497"},"modified":"2025-08-29T14:40:38","modified_gmt":"2025-08-29T14:40:38","slug":"how-to-list-users-in-linux","status":"publish","type":"post","link":"https:\/\/hostnoc-revamp.branex.org\/blog\/how-to-list-users-in-linux\/","title":{"rendered":"How to List Users in Linux?"},"content":{"rendered":"<h2><b>Understanding List Users in Linux<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Before diving into the commands, it is helpful to understand how Linux categorizes users. Broadly speaking, there are:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>System Users<\/b><span style=\"font-weight: 400;\">: These are users created by the system or during package installations. They typically run background services and processes.<\/span><span style=\"font-weight: 400;\">\n<p><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Regular Users<\/b><span style=\"font-weight: 400;\">: These are user accounts created for human users to log in and interact with the system.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Both system and regular users are stored in the <\/span><span style=\"font-weight: 400;\">\/etc\/passwd<\/span><span style=\"font-weight: 400;\"> file, along with important metadata like user ID (UID), group ID (GID), home directory and login shell.<\/span><\/p>\n<h2><b>How to List Users in Linux?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">There are multiple ways to List Users in Linux all users in a Linux system. Here are the most common and reliable methods.<\/span><\/p>\n<h3><b>1. Viewing the <\/b><b>\/etc\/passwd<\/b><b> File<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The primary method to list all users on a Linux system is by inspecting the <\/span><span style=\"font-weight: 400;\">\/etc\/passwd<\/span><span style=\"font-weight: 400;\"> file.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">cat \/etc\/passwd<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Each line in this file represents a user, formatted as:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">username:x:UID:GID:comment:home_directory:shell<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Example output:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">john:x:1001:1001:John Doe:\/home\/john:\/bin\/bash<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To extract just the usernames from the <\/span><span style=\"font-weight: 400;\">\/etc\/passwd<\/span><span style=\"font-weight: 400;\"> file:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">cut -d: -f1 \/etc\/passwd<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This will return a list of all usernames on the system including both regular and system users.<\/span><\/p>\n<h3><b>2. Using the <\/b><b>getent<\/b><b> Command<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Another method to list users in Linux is with the <\/span><span style=\"font-weight: 400;\">getent<\/span><span style=\"font-weight: 400;\"> command, which retrieves entries from administrative databases supported by the Name Service Switch (NSS). This is a more flexible approach especially in environments using Lightweight Directory Access Protocol or other authentication mechanisms.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">getent passwd<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Like <\/span><span style=\"font-weight: 400;\">cat \/etc\/passwd<\/span><span style=\"font-weight: 400;\">, this lists all users but through the NSS interface.To show only usernames:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">getent passwd | cut -d: -f1<\/span><\/p>\n<p><strong>Read more:\u00a0<a href=\"https:\/\/hostnoc-revamp.branex.org\/blog\/how-to-fix-kali-linux-black-screen\/\">How to Fix Kali Linux Black Screen?<\/a><\/strong><\/p>\n<h2><b>Filtering Regular Users<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">In Linux, user IDs (UIDs) help distinguish between system and regular users:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>System users<\/b><span style=\"font-weight: 400;\"> typically have UIDs below 1000.<\/span><span style=\"font-weight: 400;\">\n<p><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Regular users<\/b><span style=\"font-weight: 400;\"> generally have UIDs of 1000 or higher.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">To list only regular users, use:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">awk -F: &#8216;$3 &gt;= 1000 &amp;&amp; $3 &lt; 65534 { print $1 }&#8217; \/etc\/passwd<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This command filters the <\/span><span style=\"font-weight: 400;\">\/etc\/passwd<\/span><span style=\"font-weight: 400;\"> file and shows only users with UIDs in the typical range for human users.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Alternatively, using <\/span><span style=\"font-weight: 400;\">getent<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">getent passwd | awk -F: &#8216;$3 &gt;= 1000 &amp;&amp; $3 &lt; 65534 { print $1 }&#8217;<\/span><\/p>\n<p><strong>Read more:\u00a0<a href=\"https:\/\/hostnoc-revamp.branex.org\/blog\/linux-commands\/\">40 Linux Commands Every Linux User Must Master<\/a><\/strong><\/p>\n<h2><b>How to List Currently Logged-In Users?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">If you are looking to find out who is currently logged into the system, rather than a list of all accounts, use one of the following commands:<\/span><\/p>\n<h3><b>1. <\/b><b>who<\/b><b> Command<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">who<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This will show usernames, login terminals and login times.<\/span><\/p>\n<h3><b>2. <\/b><b>w<\/b><b> Command<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">w<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The <\/span><span style=\"font-weight: 400;\">w<\/span><span style=\"font-weight: 400;\"> command gives a more detailed output including the current activity of each user.<\/span><\/p>\n<h3><b>3. <\/b><b>users<\/b><b> Command<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">users<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This outputs a simple list of logged-in usernames.<\/span><\/p>\n<h2><b>How to List Usernames in Linux?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">To list only usernames (without extra information like UID or home directory), use:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">cut -d: -f1 \/etc\/passwd<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This is particularly useful for scripting or automation tasks where you need a clean list of usernames.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, to save the list to a file:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">cut -d: -f1 \/etc\/passwd &gt; all_users.txt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To count the total number of users:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">cut -d: -f1 \/etc\/passwd | wc -l<\/span><\/p>\n<h2><b>How to Get User Details in Linux?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">To get detailed information about a specific user, you can use the <\/span><span style=\"font-weight: 400;\">id<\/span><span style=\"font-weight: 400;\"> command:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">id username<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Example:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">id john<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">This might return something like:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">uid=1001(john) gid=1001(john) groups=1001(john),27(sudo)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can also check the user&#8217;s home directory and shell by using:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">getent passwd john<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Which returns a line like:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">john:x:1001:1001:John Doe:\/home\/john:\/bin\/bash<\/span><\/p>\n<h2><b>List Users with <\/b><b>compgen<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">On Bash systems, you can use <\/span><span style=\"font-weight: 400;\">compgen<\/span><span style=\"font-weight: 400;\"> to list users:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">compgen -u<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This shows all usernames known to the shell, similar to listing from <\/span><span style=\"font-weight: 400;\">\/etc\/passwd<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h3><b>Conclusion<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Whether you are using Ubuntu or another Linux distribution, knowing how to list users is a fundamental administrative skill. You can rely on \/etc\/passwd, the getent command and tools like cut, awk and compgen to explore and filter users. For real-time monitoring, tools like who, w and users help track logged-in accounts.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By mastering these commands, you will be well-equipped to manage user accounts securely and efficiently. Whether you are scripting automation tasks or maintaining server access, being able to list users in Linux is a key part of system administration.<\/span><\/p>\n<p style=\"text-align: center;\"><strong><span class=\"highlight\" style=\"background-color:#971a1d;\">Brains win battles. Power wins wars. Our servers give you both.<\/span>\n<\/strong><\/p>\n<p style=\"text-align: center;\"><section class=\"dedicated_plans_section plans-section\" id=\"dedicated_plan\">\n    <table id=\"data\" class=\"stackable large-only\">\n        <thead>\n            <tr>\n<!--                 <th class=\"tbl-head-plan\">Plan<\/th> -->\n                <th class=\"tbl-head-cores\">Cores<\/th>\n                <th class=\"tbl-head-ram\">RAM<\/th>\n                <th class=\"tbl-head-storage\">Storage<\/th>\n                <th class=\"tbl-head-plan\">Location<\/th>\n                <th class=\"tbl-head-location\">Monthly Price<\/th>\n                <th class=\"tbl-head-link\">Link<\/th>\n            <\/tr>\n        <\/thead>\n        <tbody>\n        <tr><td colspan=\"6\">No products found.<\/td><\/tr>        <\/tbody>\n    <\/table>\n<\/section>\n    <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding List Users in Linux Before diving into the commands, it is helpful to understand how Linux categorizes users. Broadly speaking, there are: System Users: These<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":13,"featured_media":13498,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[203],"tags":[],"class_list":["post-13497","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide"],"acf":[],"_links":{"self":[{"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/posts\/13497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/comments?post=13497"}],"version-history":[{"count":3,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/posts\/13497\/revisions"}],"predecessor-version":[{"id":13502,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/posts\/13497\/revisions\/13502"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/media\/13498"}],"wp:attachment":[{"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/media?parent=13497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/categories?post=13497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/tags?post=13497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}