Four Methods for viewing the current Login User information in CentOS

Source: Internet
Author: User

As a system administrator, you may often need to check which users are active in the system. Sometimes you even need to know what they are doing. This article summarizes four methods for viewing system user information (by ID.

1. Run the w command to view the process information that the logon user is using.

The w command is used to display the names of users who have logged on to the system and what they are doing. The information used by this command comes from the/var/run/utmp file. W command output information includes:

  • User Name
  • User's machine name or tty number
  • Remote Host address
  • Time when the user logs on to the system
  • Idle Time (little effect)
  • Time (JCPU time) used by the process appended to tty (Terminal)
  • Time used by the current process (PCPU time)
  • Command currently in use

W command can also use the following options

  • -H ignore header file information
  • -U: display the loading time of the result.
  • -S does not display JCPU, PCPU, Logon Time
$ w 23:04:27 up 29 days,  7:51,  3 users,  load average: 0.04, 0.06, 0.02USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHATramesh   pts/0    dev-db-server        22:57    8.00s  0.05s  0.01s sshd: ramesh [priv]jason    pts/1    dev-db-server        23:01    2:53   0.01s  0.01s -bashjohn     pts/2    dev-db-server        23:04    0.00s  0.00s  0.00s w$ w -hramesh   pts/0    dev-db-server        22:57   17:43   2.52s  0.01s sshd: ramesh [priv]jason    pts/1    dev-db-server        23:01   20:28   0.01s  0.01s -bashjohn     pts/2    dev-db-server        23:04    0.00s  0.03s  0.00s w -h$ w -u 23:22:06 up 29 days,  8:08,  3 users,  load average: 0.00, 0.00, 0.00USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHATramesh   pts/0    dev-db-server        22:57   17:47   2.52s  2.49s topjason    pts/1    dev-db-server        23:01   20:32   0.01s  0.01s -bashjohn     pts/2    dev-db-server        23:04    0.00s  0.03s  0.00s w -u$ w -s 23:22:10 up 29 days,  8:08,  3 users,  load average: 0.00, 0.00, 0.00USER     TTY      FROM               IDLE WHATramesh   pts/0    dev-db-server        17:51  sshd: ramesh [priv]jason    pts/1    dev-db-server        20:36  -bashjohn     pts/2    dev-db-server         1.00s w -s

2. Run the who command to view (log on) the user name and the started process.

The who command is used to list the names of users currently logged on to the system. The output is user name, tty number, time and date, and host address.

$ whoramesh pts/0        2009-03-28 22:57 (dev-db-server)jason  pts/1        2009-03-28 23:01 (dev-db-server)john   pts/2        2009-03-28 23:04 (dev-db-server)
If you only want to list users, you can use the following statement:

$ who | cut -d' ' -f1 | sort | uniqjohnjasonramesh
Supplement: Users command, which can be used to print the name of the user logging on to the server. In addition to the help and version options, this command has no other options. If a user uses multiple terminals, multiple duplicate user names are displayed.

$ usersjohn jason ramesh

3. Run the whoami command to view your logon name.

The whoami command is used to display the login user name.

$ whoamijohn
The running effect of the whoami command is exactly the same as that of the id-un Command, for example:

$ id -unjohn
The whoami command displays the name of the currently logged-on user and the currently used tty information. The command output includes the user name, tty name, current time and date, and the link address used by the user to log on to the system.

$ who am ijohn     pts/2        2009-03-28 23:04 (dev-db-server)$ who mom likesjohn     pts/2        2009-03-28 23:04 (dev-db-server)Warning: Don't try "who mom hates" command.
Of course, if you use the su command to change the user, the result displayed by the Command (whoami) will change accordingly.

4. view the historical information of the system at any time (user information of the system that has been used before)

The last command can be used to display the logon history of a specific user. If no parameter is specified, the historical information of all users is displayed. By default, the information displayed will be from the/var/log/wtmp file. The output result of this command contains the following columns:

  • User Name
  • Tty device number
  • Historical logon time and date
  • Logout date
  • Total working hours
$ last jasonjason   pts/0        dev-db-server   Fri Mar 27 22:57   still logged injason   pts/0        dev-db-server   Fri Mar 27 22:09 - 22:54  (00:45)jason   pts/0        dev-db-server   Wed Mar 25 19:58 - 22:26  (02:28)jason   pts/1        dev-db-server   Mon Mar 16 20:10 - 21:44  (01:33)jason   pts/0        192.168.201.11  Fri Mar 13 08:35 - 16:46  (08:11)jason   pts/1        192.168.201.12  Thu Mar 12 09:03 - 09:19  (00:15)jason   pts/0        dev-db-server   Wed Mar 11 20:11 - 20:50  (00:39

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.