{"id":4241,"date":"2019-10-25T04:21:16","date_gmt":"2019-10-25T04:21:16","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=4241"},"modified":"2026-03-10T10:24:56","modified_gmt":"2026-03-10T10:24:56","slug":"how-to-list-users-in-linux","status":"publish","type":"post","link":"\/in\/tutorials\/how-to-list-users-in-linux","title":{"rendered":"How to list users in Linux: Commands, tools, and automation tips"},"content":{"rendered":"<p>To list users in Linux, the most common method is to read the <strong>\/etc\/passwd<\/strong> file, which stores essential information about every account on the system.<\/p><p>Listing users is a basic system administration task. It helps you check who&rsquo;s logged in, filter accounts by ID, and automate audits to maintain strong system security.<\/p><p>Here&rsquo;s a summary of the commands you can use to list Linux users:<\/p><ol class=\"wp-block-list\">\n<li><strong>cat<\/strong>. Best for a quick, raw view of all local users.<\/li>\n\n\n\n<li><strong>getent<\/strong>. Ideal for listing users from both local and network databases like LDAP.<\/li>\n\n\n\n<li><strong>compgen<\/strong>. Useful for generating a clean list of usernames for scripting and autocompletion.<\/li>\n\n\n\n<li><strong>awk<\/strong> and <strong>cut<\/strong>. Best for filtering output to show only usernames.<\/li>\n\n\n\n<li><strong>who<\/strong> and <strong>users<\/strong>. Used to check which users are currently logged in.<\/li>\n<\/ol><p>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-prerequisites-for-listing-linux-users\">Prerequisites for listing Linux users<\/h2><p>Before listing users in Linux, make sure you have a terminal connection. This requirement applies whether you&rsquo;re working on a local machine or managing a remote system like a virtual private server (VPS).<\/p><p>If you&rsquo;re managing a VPS, connect through an SSH client using the following syntax:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh username@your_server_ip<\/pre><p>Any user can read the <strong>\/etc\/passwd<\/strong> file and run basic listing commands. But administrative actions, such as creating, modifying, or deleting users, require <strong>root<\/strong> or <strong>sudo<\/strong> access.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-list-users-using-the-cat-command\">How to list users using the cat command<\/h2><p>The simplest way to list all users is to output the contents of the <strong>\/etc\/passwd<\/strong> file using the <strong>cat<\/strong> command. This file contains attributes for every user in the system, including system accounts and regular users.<\/p><p>Run the following command to display the file:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cat \/etc\/passwd<\/pre><p>The output shows one line per user account.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e084de870b6\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/10\/terminal-cat-etc-passwd-1024x602.png\" alt=\"Terminal displaying cat \/etc\/passwd output with Linux user list\" class=\"wp-image-137111\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Each line follows this structure:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">username:x:UID:GID:GECOS:home_directory:shell<\/pre><p>Here&rsquo;s what each field represents:<\/p><ul class=\"wp-block-list\">\n<li><strong>username<\/strong>. The login name for the account.<\/li>\n\n\n\n<li><strong>x<\/strong>. A placeholder indicating that the password hash is stored in <strong>\/etc\/shadow<\/strong>.<\/li>\n\n\n\n<li><strong>UID<\/strong>. The numeric user ID.<\/li>\n\n\n\n<li><strong>GID<\/strong>. The numeric primary group ID.<\/li>\n\n\n\n<li><strong>GECOS<\/strong>. Optional user information, such as a full name or description.<\/li>\n\n\n\n<li><strong>home_directory<\/strong>. The absolute path to the user&rsquo;s home directory.<\/li>\n\n\n\n<li><strong>shell<\/strong>. The program that runs when the user logs in.<\/li>\n<\/ul><p>Using <strong>cat<\/strong> on systems with hundreds of users can produce cluttered output. In this case, you can pipe the results through <strong>less<\/strong> for easier reading or use <a href=\"\/in\/tutorials\/grep-command-in-linux\">grep<\/a> to find specific accounts.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cat \/etc\/passwd | less<\/pre><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cat \/etc\/passwd | grep username<\/pre><p>Since <strong>\/etc\/passwd<\/strong> is world-readable, be mindful that it exposes user IDs and home directory paths. But passwords remain safely encrypted in <strong>\/etc\/shadow<\/strong>, which only root can read.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-list-linux-users-using-the-getent-command\">How to list Linux users using the getent command<\/h2><p>The <strong>getent<\/strong> command fetches entries from the system&rsquo;s Name Service Switch (NSS) libraries, making it ideal for systems that use network-based user directories such as LDAP or Active Directory.<\/p><p>Unlike <strong>cat<\/strong>, which only reads the local <strong>\/etc\/passwd<\/strong> file, <strong>getent<\/strong> queries all configured user databases as defined in <strong>\/etc\/nsswitch.conf<\/strong>.<\/p><p>To list all users from both local and network sources, run:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">getent passwd<\/pre><p>If you need to check the details of a specific user, append the username:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">getent passwd username<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e084de89b0a\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/10\/terminal-getent-etc-passwd-username-1024x108.png\" alt=\"Terminal showing getent passwd username output for a Linux user\" class=\"wp-image-137112\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>The output format matches<strong> \/etc\/passwd<\/strong>, but <strong>getent<\/strong> shows user data from every connected service, not just local accounts.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-use-compgen-to-list-users\">How to use compgen to list users<\/h2><p>The <strong>compgen<\/strong> command is a built-in Bash command that generates completion matches. When used with the <strong>-u<\/strong> option, it outputs all usernames known to the system, including both regular and system accounts.<\/p><p>To list all usernames, run:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">compgen -u<\/pre><p><strong>compgen<\/strong> queries the same NSS databases as <strong>getent<\/strong>, but it outputs only usernames without any additional fields. This makes it especially useful for shell scripting or setting up autocompletion features in custom tools.<\/p><p>By default, compgen prints a long vertical list. To make the output easier to read, pipe it into the <strong>column<\/strong> command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">compgen -u | column<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e084de8bdb9\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/10\/terminal-compgen-u-column-1024x1009.png\" alt=\"Terminal showing compgen -u | column output with listed usernames\" class=\"wp-image-137113\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p><div><p class=\"important\"><strong>Important!<\/strong> Because <strong>compgen<\/strong> is a built-in Bash command, it isn&rsquo;t available in other shells, such as <strong>sh<\/strong> or <strong>zsh<\/strong>.<\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-list-users-with-awk-and-cut-commands-for-custom-output\">How to list users with awk and cut commands for custom output<\/h2><p>To extract only usernames or other specific fields without the clutter of IDs and directory paths, use text-processing utilities such as <strong>awk<\/strong> or <strong>cut<\/strong>.<\/p><p>These tools act as filters. They take the raw data from <strong>\/etc\/passwd<\/strong> and display only the fields you request.<\/p><p>Here&rsquo;s a comparison of how to use both commands for listing users:<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>Feature<\/strong><\/td><td><strong>awk<\/strong><\/td><td><strong>cut<\/strong><\/td><\/tr><tr><td>Syntax<\/td><td><strong>awk -F: &lsquo;{ print $1}&rsquo; \/etc\/passwd<\/strong><\/td><td><strong>cut -d: -f1 \/etc\/passwd<\/strong><\/td><\/tr><tr><td>Delimiter<\/td><td>Uses <strong>-F:<\/strong> to set the colon as a separator<\/td><td>Uses <strong>-d:<\/strong> to set the colon as a separator<\/td><\/tr><tr><td>Field logic<\/td><td>Prints <strong>$1<\/strong> (the first field)<\/td><td>Selects <strong>-f1<\/strong> (the first field)<\/td><\/tr><tr><td>Best for<\/td><td>Complex formatting and conditional processing<\/td><td>Simple, lightweight field extraction<\/td><\/tr><\/tbody><\/table><\/figure><p>Use <a href=\"\/in\/tutorials\/awk-command\">awk<\/a> if you plan to apply further processing, such as filtering users by a UID range.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e084de8e272\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/10\/terminal-awk-f-print-1-etc-passwd-1024x883.png\" alt=\"Terminal showing awk -F: '{print }' \/etc\/passwd username output\" class=\"wp-image-137114\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Use <a href=\"\/in\/tutorials\/linux-cut-command\">cut<\/a> if you need a quick solution to extract only usernames.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e084de907f9\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/10\/terminal-cut-d-f1-etc-passwd-961x1024.png\" alt=\"Terminal showing cut -d: -f1 \/etc\/passwd output listing usernames\" class=\"wp-image-137115\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-how-to-check-currently-logged-in-users\">How to check currently logged-in users<\/h2><p>To see who is currently active in a session, rather than listing every registered account, use the <strong>who<\/strong> or <strong>users<\/strong> commands.<\/p><p>Listing all users with tools like <strong>cat<\/strong> shows everyone who can log in, while <strong>who<\/strong> and <strong>users<\/strong> show who is logged in at that moment. This distinction matters when you&rsquo;re monitoring activity on multi-user servers.<\/p><ul class=\"wp-block-list\">\n<li><strong>users<\/strong>. Displays a simple line of currently logged-in usernames.<\/li>\n<\/ul><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">users<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e084de92dce\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/10\/terminal-users-1024x198.png\" alt=\"Terminal showing users command output with active usernames\" class=\"wp-image-137116\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ul class=\"wp-block-list\">\n<li><strong>who<\/strong>. Provides detailed information, including the terminal line, login time, and originating IP address.<\/li>\n<\/ul><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e084de95096\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/10\/terminal-who-1024x80.png\" alt=\"Terminal displaying who command details for logged-in users\" class=\"wp-image-137117\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>For even more detail, including idle time and running processes, use the <strong>w<\/strong> command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">w<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e084de97373\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/10\/terminal-w-1024x119.png\" alt=\"Terminal showing w command output with user and process details\" class=\"wp-image-137118\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-what-are-the-best-practices-for-effective-user-listing\">What are the best practices for effective user listing?<\/h2><p>Effective user listing involves filtering output for readability, securing user data, and automating regular checks to maintain system integrity.<\/p><h3 class=\"wp-block-heading\" id=\"h-combine-commands-with-pipes\"><strong>Combine commands with pipes<\/strong><\/h3><p>To find specific information quickly, combine listing commands with <strong>grep<\/strong>. For example, to check whether a specific user exists without scrolling through the entire list:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">getent passwd | grep username<\/pre><p>You can also sort the list alphabetically to make manual auditing easier:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cut -d: -f1 \/etc\/passwd | sort<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e084de99927\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/10\/terminal-cut-d-f1-etc-passwd-sort-1024x932.png\" alt=\"Terminal showing cut -d: -f1 \/etc\/passwd | sort sorted user list\" class=\"wp-image-137119\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-use-a-gui-for-user-management\"><strong>Use a GUI for user management<\/strong><\/h3><p>If you prefer a visual interface over the command line, use a control panel such as Webmin or the native user manager in your desktop environment.<\/p><p>These tools often provide a searchable table of users, which makes it easier to view groups, IDs, and shell permissions at a glance without memorizing command syntax.<\/p><h3 class=\"wp-block-heading\" id=\"h-manage-user-information-securely\"><strong>Manage user information securely<\/strong><\/h3><p>Regularly listing users is a key security habit. When reviewing the list, look for:<\/p><ul class=\"wp-block-list\">\n<li><strong>Unknown accounts<\/strong>. Users you didn&rsquo;t create.<\/li>\n\n\n\n<li><strong>Unexpected UID 0 accounts<\/strong>. Only root should have UID 0. Any other UID 0 account has full superuser privileges.<\/li>\n\n\n\n<li><strong>Shell access<\/strong>. Verify that system users (such as <strong>www-data<\/strong> or <strong>nobody<\/strong>) use<strong> \/usr\/sbin\/nologin<\/strong> (Debian\/Ubuntu), <strong>\/sbin\/nologin<\/strong> (RHEL\/CentOS), or <strong>\/bin\/false<\/strong> to prevent interactive login.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-how-to-automate-user-listing-with-bash-scripts\">How to automate user listing with Bash scripts<\/h2><p>To automate user listing, create Bash scripts that execute commands like <strong>cut<\/strong> or <strong>awk<\/strong> and schedule them with <strong>cron<\/strong>.<\/p><p>While listing users with commands such as <strong>cat<\/strong>, <strong>getent<\/strong>, <strong>awk<\/strong>, <strong>cut<\/strong>, <strong>who<\/strong>, and <strong>compgen<\/strong> works well for quick checks, it becomes inefficient on large Linux systems because it requires repetitive, manual steps.<\/p><p>Creating Bash scripts lets you automate user retrieval, filter accounts based on specific criteria (such as users with <strong>sudo<\/strong> access), and save reports for later review. This approach ensures consistent, secure auditing across long-term server management.<\/p><p>You can then schedule these scripts with <a href=\"\/in\/tutorials\/cron-job\">cron jobs<\/a> to automatically catch suspicious account changes. A simple script can export all users to a timestamped text file, so you can compare results over time.<\/p><p>Here&rsquo;s an example script that saves a user list generated with <strong>cut<\/strong>, with basic error handling:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n# Export user list to a timestamped file\n\nOUTPUT_DIR=\"$HOME\/user_audits\"\nOUTPUT_FILE=\"$OUTPUT_DIR\/user_audit_$(date +%F).txt\"\n\n# Create output directory if it doesn't exist\nmkdir -p \"$OUTPUT_DIR\"\n\n# Generate user list\ncut -d: -f1 \/etc\/passwd | sort &gt; \"$OUTPUT_FILE\"\n\necho \"User audit saved to $OUTPUT_FILE\"<\/pre><p>Make the script executable and schedule it with cron to run daily or weekly:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">chmod +x ~\/user_audit.sh\ncrontab -e\n# Add: 0 2 * * * ~\/user_audit.sh<\/pre><p>If you&rsquo;re not comfortable writing scripts from scratch, you can use <strong>Kodee<\/strong>, Hostinger&rsquo;s AI assistant. It&rsquo;s available on all <a href=\"\/in\/vps-hosting\">VPS plans<\/a> and generates automation scripts instantly. Just type a prompt describing what you want the script to do.<\/p><p>For more hands-on learning, explore our guide on <a href=\"\/in\/tutorials\/bash-script-example\">bash script examples<\/a> to see how to structure advanced automation tasks.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/in\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/in\/tutorials\/wp-content\/uploads\/sites\/52\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>To list users in Linux, the most common method is to read the \/etc\/passwd file, which stores essential information about every account on the system. Listing users is a basic system administration task. It helps you check who&rsquo;s logged in, filter accounts by ID, and automate audits to maintain strong system security. Here&rsquo;s a summary [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/in\/tutorials\/how-to-list-users-in-linux\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":128783,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"","rank_math_description":"","rank_math_focus_keyword":"","footnotes":""},"categories":[22644,22640],"tags":[],"class_list":["post-4241","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-list-users-in-linux","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/lister-utilisateurs-linux","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/como-ver-usuarios-en-linux","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-cek-user-linux","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-list-users-in-linux","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-list-users-in-linux","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-list-users-in-linux","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/como-ver-usuarios-en-linux","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/como-ver-usuarios-en-linux","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/como-ver-usuarios-en-linux","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-list-users-in-linux","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-list-users-in-linux","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-list-users-in-linux","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-list-users-in-linux","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/4241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/comments?post=4241"}],"version-history":[{"count":48,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/4241\/revisions"}],"predecessor-version":[{"id":128781,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/posts\/4241\/revisions\/128781"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media\/128783"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/media?parent=4241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/categories?post=4241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/in\/tutorials\/wp-json\/wp\/v2\/tags?post=4241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}