1. Use the w command to view the user is using the login process information
w command displays the name of the user has logged into the system, and what they are doing. This command uses information from / var / run / utmp file. W command output information comprises:
- user name
- Tty user's machine name or number
- Remote host address
- Time user login system
- Idle time (not very useful)
- To the Time TTY (terminal) used in the process (JCPU time)
- The current process used time (PCPU time)
- User is currently using the command
w commands can also use the following options
- -h ignore the header file information
- -u displays the results of load time
- -s Do not show JCPU, PCPU, login time
$ w 23:04:27 up 29 days, 7:51, 3 users, load average: 0.04, 0.06, 0.02 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ramesh 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 -bash john pts/2 dev-db-server 23:04 0.00s 0.00s 0.00s w $ w -h ramesh 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 -bash john 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.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ramesh pts/0 dev-db-server 22:57 17:47 2.52s 2.49s top jason pts/1 dev-db-server 23:01 20:32 0.01s 0.01s -bash john 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.00 USER TTY FROM IDLE WHAT ramesh pts/0 dev-db-server 17:51 sshd: ramesh [priv] jason pts/1 dev-db-server 20:36 -bash john pts/2 dev-db-server 1.00s w -s
2. Use the who command to view (login) user name and the start of the process
who command lists the user name of the currently logged on the system. Its output is: user name, tty number, time and date, host address.
$ who ramesh 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 | uniq john jason rameshSupplementary : users command can be used to print out the name of the user logon server. The command in addition to help and version options, has no other options. If a user uses a plurality of terminals, a corresponding plurality of displays duplicate user name.
$ users john jason ramesh
3. Use the whoami command to view the login name you are using
whoami command is used to display the user login name.
$ whoami johnThe effect of the implementation and effect of the whoami command id -un exactly the same, for example:
$ id -un johnwhoami command displays the name of the user currently logged in, and currently used tty information. The output of the command include the following: user name, tty name, current date and time, and also includes a link address of the user login system used.
$ who am i john pts/2 2009-03-28 23:04 (dev-db-server) $ who mom likes john pts/2 2009-03-28 23:04 (dev-db-server) Warning: Don't try "who mom hates" command.当然,如果你使用su命令改变用户,则该命令(whoami)所显示的结果将随之改变。
4. 随时查看系统的历史信息(曾经使用过系统的用户信息)
last命令可用于显示特定用户登录系统的历史记录。如果没有指定任何参数,则显示所有用户的历史信息。在默认情况下,这些信息(所显示的信息)将来源于/var/log/wtmp文件。该命令的输出结果包含以下几列信息:
- 用户名称
- tty设备号
- 历史登录时间日期
- 登出时间日期
- 总工作时间
$ last jason jason pts/0 dev-db-server Fri Mar 27 22:57 still logged in jason 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