{"id":12139,"date":"2019-03-22T11:50:30","date_gmt":"2019-03-22T11:50:30","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12139"},"modified":"2019-03-22T11:50:30","modified_gmt":"2019-03-22T11:50:30","slug":"11-ways-to-find-user-account-info-and-login-details-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/11-ways-to-find-user-account-info-and-login-details-in-linux\/","title":{"rendered":"11 Ways to Find User Account Info and Login Details in Linux"},"content":{"rendered":"<p>This article will show you eleven useful ways to find the information about users on a Linux system. Here we\u2019ll describe commands to get a user\u2019s account details, show login details as well as what users are doing on the system.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/monitor-linux-commands-executed-by-system-users-in-real-time\/\" target=\"_blank\" rel=\"noopener\">How to Monitor Linux Commands Executed by System Users in Real-time<\/a><\/p>\n<p>If you want to add users in Linux, use the\u00a0<a href=\"https:\/\/www.tecmint.com\/add-users-in-linux\/\" target=\"_blank\" rel=\"noopener\">useradd utility<\/a>, and to modify or change any attributes of a already created user account, use the\u00a0<a href=\"https:\/\/www.tecmint.com\/usermod-command-examples\/\" target=\"_blank\" rel=\"noopener\">usermod<\/a>\u00a0via the command line as explained in the following guides:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/add-users-in-linux\/\" target=\"_blank\" rel=\"noopener\">15 Useful Practical Examples on \u2018useradd\u2019 Command<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/usermod-command-examples\/\" target=\"_blank\" rel=\"noopener\">15 Useful Practical Examples on \u2018usermod\u2019 Command<\/a><\/li>\n<\/ol>\n<p>We\u2019ll start by looking at commands to find a user\u2019s account information, then proceed to explain commands to view login details.<\/p>\n<h3>1. id Command<\/h3>\n<p><strong>id<\/strong>\u00a0is a simple command line utility for displaying a real and effective user and group IDs as follows.<\/p>\n<pre><strong>$ id tecmint<\/strong> \r\n\r\nuid=1000(tecmint) gid=1000(tecmint) groups=1000(tecmint),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),130(sambashare)\r\n<\/pre>\n<h3>2. groups Command<\/h3>\n<p><strong>groups<\/strong>\u00a0command is used to show all the groups a user belongs to like this.<\/p>\n<pre><strong>$ groups tecmint<\/strong>\r\n\r\ntecmint : tecmint adm cdrom sudo dip plugdev lpadmin sambashare\r\n<\/pre>\n<h3>3. finger Command<\/h3>\n<p><strong>finger<\/strong>\u00a0command is used to search information about a user on Linux. It doesn\u2019t come per-installed on many Linux systems.<\/p>\n<p>To install it on your system, run this command on the terminal.<\/p>\n<pre>$ sudo apt install finger\t#Debian\/Ubuntu \r\n$ sudo yum install finger\t#RHEL\/CentOS\r\n$ sudo dnf install finger\t#Fedora 22+\r\n<\/pre>\n<p>It shows a user\u2019s real name; home directory; shell; login: name, time; and so much more as below.<\/p>\n<pre><strong>$ finger tecmint<\/strong>\r\n\r\nLogin: tecmint        \t\t\tName: TecMint\r\nDirectory: \/home\/tecmint            \tShell: \/bin\/bash\r\nOn since Fri Sep 22 10:39 (IST) on tty8 from :0\r\n   2 hours 1 minute idle\r\nNo mail.\r\nNo Plan.\r\n<\/pre>\n<h3>4. getent Command<\/h3>\n<p><strong>getent<\/strong>\u00a0is a command line utility for fetching entries from\u00a0<strong>Name Service Switch<\/strong>\u00a0(<strong>NSS<\/strong>) libraries from a specific system database.<\/p>\n<p>To get a user\u2019s account details, use the\u00a0<strong>passwd<\/strong>\u00a0database and the\u00a0<strong>username<\/strong>\u00a0as follows.<\/p>\n<pre><strong>$ getent passwd tecmint<\/strong>\r\n\r\ntecmint:x:1000:1000:TecMint,,,:\/home\/tecmint:\/bin\/bash\r\n<\/pre>\n<h3>5. grep Command<\/h3>\n<p><a href=\"https:\/\/www.tecmint.com\/12-practical-examples-of-linux-grep-command\/\" target=\"_blank\" rel=\"noopener\">grep command<\/a>\u00a0is a powerful pattern searching tool available on most if not all Linus systems. You can use it to find information about a specific user from the system accounts file:\u00a0<strong>\/etc\/passwd<\/strong>\u00a0as shown below.<\/p>\n<pre><strong>$ grep -i tecmint \/etc\/passwd<\/strong>\r\n\r\ntecmint:x:1000:1000:TecMint,,,:\/home\/tecmint:\/bin\/bash\r\n<\/pre>\n<h3>6. lslogins Command<\/h3>\n<p><strong>lslogins command<\/strong>\u00a0shows information about known users in the system, the\u00a0<code>-u<\/code>\u00a0flag only displays user accounts.<\/p>\n<pre><strong>$ lslogins -u<\/strong>\r\n\r\nUID USER       PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS\r\n   0 root        144                              root\r\n1000 tecmint      70                     10:39:07 TecMint,,,\r\n1001 aaronkilik    0                              \r\n1002 john          0                              John Doo\r\n<\/pre>\n<h3>7. users Command<\/h3>\n<p><strong>users command<\/strong>\u00a0shows the usernames of all users currently logged on the system like so.<\/p>\n<pre><strong>$ users<\/strong>\r\n\r\ntecmint\r\naaron\r\n<\/pre>\n<h3>8. who Command<\/h3>\n<p><strong>who command<\/strong>\u00a0is used to display users who are logged on the system, including the terminals they are connecting from.<\/p>\n<pre><strong>$ who -u<\/strong>\r\n\r\ntecmint  tty8         2017-09-22 10:39 02:09        2067 (:0)\r\n<\/pre>\n<h3>9. w Command<\/h3>\n<p><strong>w command<\/strong>\u00a0shows all users who are logged on the system and what they are doing.<\/p>\n<pre><strong>$ w<\/strong>\r\n\r\n12:46:54 up  2:10,  1 user,  load average: 0.34, 0.44, 0.57\r\nUSER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT\r\ntecmint  tty8     :0               10:39    2:10m  4:43   0.46s cinnamon-sessio\r\n<\/pre>\n<h3>10. last or lastb commands<\/h3>\n<p><strong>last\/lastb commands<\/strong>\u00a0displays a list of last logged in users on the system.<\/p>\n<pre><strong>$ last<\/strong> \r\nOR\r\n<strong>$ last -a<\/strong>   #show hostname on the last column\r\n<\/pre>\n<div class=\"code-label\">List of Last Logged Users<\/div>\n<pre>tecmint  tty8         Fri Sep 22 10:39    gone - no logout  :0\r\nreboot   system boot  Fri Sep 22 10:36   still running      4.4.0-21-generic\r\ntecmint  tty8         Thu Sep 21 10:44 - down   (06:56)     :0\r\nreboot   system boot  Thu Sep 21 10:42 - 17:40  (06:58)     4.4.0-21-generic\r\ntecmint  tty8         Wed Sep 20 10:19 - down   (06:50)     :0\r\nreboot   system boot  Wed Sep 20 10:17 - 17:10  (06:52)     4.4.0-21-generic\r\ntecmint  pts\/14       Tue Sep 19 15:15 - 15:16  (00:00)     tmux(14160).%146\r\ntecmint  pts\/13       Tue Sep 19 15:15 - 15:16  (00:00)     tmux(14160).%145\r\n...\r\n<\/pre>\n<p>To show all the users who were present at a specified time, use the\u00a0<code>-p<\/code>\u00a0option as follows.<\/p>\n<pre><strong>$ last -ap now<\/strong>\r\n\r\ntecmint  tty8         Fri Sep 22 10:39    gone - no logout  :0\r\nreboot   system boot  Fri Sep 22 10:36   still running      4.4.0-21-generic\r\n\r\nwtmp begins Fri Sep  1 16:23:02 2017\r\n<\/pre>\n<h3>11. lastlog Command<\/h3>\n<p><strong>lastlog command<\/strong>\u00a0is used to find the details of a recent login of all users or of a given user as follows.<\/p>\n<pre><strong>$ lastlog<\/strong>  \r\nOR\r\n<strong>$ lastlog -u tecmint<\/strong> \t#show lastlog records for specific user tecmint\r\n<\/pre>\n<div class=\"code-label\">Records of Recent Logged Users<\/div>\n<pre>Username         Port     From             Latest\r\nroot                                       **Never logged in**\r\nkernoops                                   **Never logged in**\r\npulse                                      **Never logged in**\r\nrtkit                                      **Never logged in**\r\nsaned                                      **Never logged in**\r\nusbmux                                     **Never logged in**\r\nmdm                                        **Never logged in**\r\ntecmint          pts\/1    127.0.0.1        Fri Jan  6 16:50:22 +0530 2017\r\n..\r\n<\/pre>\n<p>That\u2019s it! If you know any other command-line trick or command to view user account details do share with us.<\/p>\n<p>You\u2019ll find these related article so useful:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/rhcsa-exam-manage-users-and-groups\/\" target=\"_blank\" rel=\"noopener\">How to Manage Users and Groups in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/delete-remove-a-user-account-with-home-directory-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Delete User Accounts with Home Directory in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/change-a-users-default-shell-in-linux\/\" target=\"_blank\" rel=\"noopener\">3 Ways to Change Default User Shell in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/block-or-disable-normal-user-logins-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Block or Disable User Logins in Linux<\/a><\/li>\n<\/ol>\n<p>In this article, we\u2019ve explained various ways to find information about users and login details on a Linux system.<\/p>\n<p>&nbsp;<br \/>\n<a href=\"https:\/\/www.tecmint.com\/find-user-account-info-and-login-details-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article will show you eleven useful ways to find the information about users on a Linux system. Here we\u2019ll describe commands to get a user\u2019s account details, show login details as well as what users are doing on the system. Read Also:\u00a0How to Monitor Linux Commands Executed by System Users in Real-time If you &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/22\/11-ways-to-find-user-account-info-and-login-details-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;11 Ways to Find User Account Info and Login Details in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12139","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12139"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12139\/revisions"}],"predecessor-version":[{"id":12140,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12139\/revisions\/12140"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}