{"id":358,"date":"2014-07-11T22:53:34","date_gmt":"2014-07-11T22:53:34","guid":{"rendered":"https:\/\/qbytes.cloud\/?p=358"},"modified":"2014-07-11T22:53:34","modified_gmt":"2014-07-11T22:53:34","slug":"who-is-logged-in-on-your-linux-system","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2014\/07\/11\/who-is-logged-in-on-your-linux-system\/","title":{"rendered":"Who is Logged-In on Your Linux System"},"content":{"rendered":"<p>w command is used to show logged-in user names and what they are doing. The information will be read from \/var\/run\/utmp file. The output of the w command contains the following columns:<\/p>\n<p>    Name of the user<br \/>\n    User\u2019s machine number or tty number<br \/>\n    Remote machine address<br \/>\n    User\u2019s Login time<br \/>\n    Idle time (not usable time)<br \/>\n    Time used by all processes attached to the tty (JCPU time)<br \/>\n    Time used by the current process (PCPU time)<br \/>\n    Command currently getting executed by the users<\/p>\n<p>Following options can be used for the w command:<\/p>\n<p>    -h Ignore the header information<br \/>\n    -u Display the load average (uptime output)<br \/>\n    -s Remove the JCPU, PCPU, and login time.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# w\n 15:46:21 up 23 days, 1 min,  1 user,  load average: 0.00, 0.00, 0.00\nUSER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT\nroot     pts\/0    66.226.xx.x    15:46    0.00s  0.06s  0.00s w\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# w -h\nroot     pts\/0    66.226.79.7      15:46    0.00s  0.06s  0.00s w -h\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# w -u\n 15:47:05 up 23 days, 2 min,  1 user,  load average: 0.00, 0.00, 0.00\nUSER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT\nroot     pts\/0    66.226.79.7      15:46    0.00s  0.06s  0.00s w -u\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# w -s\n 15:47:23 up 23 days, 2 min,  1 user,  load average: 0.00, 0.00, 0.00\nUSER     TTY      FROM               IDLE WHAT\nroot     pts\/0    66.226.79.7       0.00s w -s\n\n<\/pre>\n<p>2. Get the user name and process of logged in user using who and users command<\/p>\n<p>who command is used to get the list of the usernames who are currently logged in. Output of the who command contains the following columns: user name, tty number, date and time, machine address.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# who\nroot     pts\/0        2014-07-11 15:46 (66.226.79.7)\n\n<\/pre>\n<p>To get a list of all usernames that are currently logged in, use the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# who | cut -d&#039; &#039; -f1 | sort | uniq\nroot\n\n<\/pre>\n<p>Users Command<\/p>\n<p>users command is used to print the user name who are all currently logged in the current host. It is one of the command don\u2019t have any option other than help and version. If the user using, \u2018n\u2019 number of terminals, the user name will shown in \u2018n\u2019 number of time in the output.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# users\nroot\n<\/pre>\n<p>3. Get the username you are currently logged in using whoami. whoami command is used to print the loggedin user name.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# whoami\nroot\n\n<\/pre>\n<p>whoami command gives the same output as id -un as shown below:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# id -un\nroot\n\n<\/pre>\n<p>who am i command will display the logged-in user name and current tty details. The output of this command contains the following columns: logged-in user name, tty name, current time with date and ip-address from where this users initiated the connection.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# who am i\nroot     pts\/0        2014-07-11 15:46 (66.226.79.7)\n\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\n&#x5B;root@austin ~]# who mom likes\nroot     pts\/0        2014-07-11 15:46 (66.226.79.7)\n\n<\/pre>\n<p>Warning: Don&#8217;t try &#8220;who mom hates&#8221; command.<\/p>\n<p>Also, if you do su to some other user, this command will give the information about the logged in user name details.<\/p>\n<p>4. Get the user login history at any time<\/p>\n<p>last command will give login history for a specific username. If we don\u2019t give any argument for this command, it will list login history for all users. By default this information will read from \/var\/log\/wtmp file. The output of this command contains the following columns:<\/p>\n<p>    User name<br \/>\n    Tty device number<br \/>\n    Login date and time<br \/>\n    Logout time<br \/>\n    Total working time<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n&#x5B;root@austin ~]# last\nroot     pts\/0        10.1.xx.x    Sat Aug  3 06:49 - down   (00:01)\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>w command is used to show logged-in user names and what they are doing. The information will be read from \/var\/run\/utmp file. The output of the w command contains the following columns: Name of the user User\u2019s machine number or tty number Remote machine address User\u2019s Login time Idle time (not usable time) Time used &#8230; <a title=\"Who is Logged-In on Your Linux System\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2014\/07\/11\/who-is-logged-in-on-your-linux-system\/\" aria-label=\"Read more about Who is Logged-In on Your Linux System\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-358","post","type-post","status-publish","format-standard","hentry","category-administration"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}