码迷,mamicode.com
首页 > 其他好文 > 详细

w、who、last、lastbon、lastlog显示登录命令用法

时间:2018-05-26 19:36:05      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:apr   忽略   mes   who   highlight   ftp   pac   tor   test   

一、w 显示已登录用户信息和用户正在执行命令

1.命令功能

w可以显示已登录系统的用户,并显示用户正在执行的命令

2.语法格式

w option user

选项说明

选项

选项说明

-h

不显示前两行标题信息

-u

忽略执行程序的名称,以及cpu时间的信息

-s

使用段输出格式

3.使用范例

范例1 显示已登录账号信息

[root@cxf ~]# w
 02:33:50 up 26 min,  2 users,  load average: 0.08, 0.03, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    172.16.2.100     02:07   11.00s  0.12s  0.01s top
root     pts/1    172.16.2.100     02:33    0.00s  0.00s  0.00s w

范例2 w结合-h选项

[root@cxf ~]# w -h
root     pts/0    172.16.2.100     02:07    5.00s  0.26s  0.15s top   #执行命令
root     pts/1    172.16.2.100     02:33    0.00s  0.00s  0.00s w -h

二、who 显示已登录信息

1.命令功能

who显示已登录系统的账号,以及系统的启动时间等信息。

2.语法格式

who option

选项说明

选项

选项说明

-a

显示说有信息,相当于 –b –d –login –p –r –t –T –u

-b

显示系统的启动时间

-d

显示已死的进程

-H

显示标题,默认不显示

-l

显示登录进程

3.使用范例

范例1  显示已登录用户的全部信息

[root@cxf ~]# who 
root     pts/0        2018-05-21 02:07 (172.16.2.100)
root     pts/1        2018-05-21 02:33 (172.16.2.100)
[root@cxf ~]# who -a
           系统引导 2018-05-21 02:07
           运行级别 3 2018-05-21 02:07
登录     tty1         2018-05-21 02:07              1431 id=1
登录     tty2         2018-05-21 02:07              1433 id=2
登录     tty3         2018-05-21 02:07              1435 id=3
登录     tty4         2018-05-21 02:07              1438 id=4
登录     tty5         2018-05-21 02:07              1440 id=5
登录     tty6         2018-05-21 02:07              1442 id=6
root     + pts/0        2018-05-21 02:07 00:06        1445 (172.16.2.100)
root     + pts/1        2018-05-21 02:33   .          1633 (172.16.2.100)

范例2 显示系统启动时间

[root@cxf ~]# who -b
         系统引导 2018-05-21 02:07

三、last 显示用户登录列表

1.命令功能

last能够从日志文件/var/log/wtmp读取信息并显示用户最近登录列表

2.语法格式

last  option 

3.使用范例

范例1

[root@cxf ~]# last
root     pts/0        172.16.2.100     Mon May 21 02:42   still logged in   
root     pts/1        172.16.2.100     Mon May 21 02:33   still logged in   
root     pts/1        172.16.2.100     Mon May 21 02:10 - 02:33  (00:23)    
root     pts/0        172.16.2.100     Mon May 21 02:07 - 02:42  (00:34)   
...
root     tty1                          Thu Apr  7 19:49 - down   (00:44)    
reboot   system boot  2.6.32-642.el6.x Thu Apr  7 19:48 - 20:33  (00:45)    

wtmp begins Sat Mar 19 12:15:21 2016

范例2 显示指定用户的登录情况

[root@cxf ~]# last joe
joe      tty1                          Sat Apr 14 19:33 - crash  (00:05)    
joe      tty1                          Sat Apr 14 19:27 - crash  (00:05)    

wtmp begins Sat Mar 19 12:15:21 2016

四、lastb 显示用户登录失败记录

1.命令功能

lastb从日志文件/var/log/btmp中读取信息,并显示用户登录失败的记录,用于发现系统登录异常。

2.语法格式

lastb  option

3.使用范例

[root@cxf ~]# lastb
chu      ssh:notty    172.16.2.100     Mon May 21 02:58 - 02:58  (00:00)    
chu      ssh:notty    172.16.2.100     Mon May 21 02:58 - 02:58  (00:00)    
chu      ssh:notty    172.16.2.100     Mon May 21 02:58 - 02:58  (00:00)    
chu      ssh:notty    172.16.2.100     Mon May 21 02:58 - 02:58  (00:00)   

五、lastlog 显示说有用户的最近登录记录

1.命令功能

lastlog 从日志文件/var/log/lastlog文件中读取信息,并显示所有用户最近登录记录,用户查看信通私有存在异常登录。

2.语法格式

lastlog  option

3.使用范例

[root@cxf ~]# lastlog
用户名           端口     来自             最后登陆时间
root             pts/0    172.16.2.100     一 5月 21 02:57:38 +0800 2018
bin                                        **从未登录过**
daemon                                     **从未登录过**
adm                                        **从未登录过**
lp                                         **从未登录过**
sync                                       **从未登录过**
shutdown                                   **从未登录过**
halt                                       **从未登录过**
mail                                       **从未登录过**
uucp                                       **从未登录过**
operator                                   **从未登录过**
games                                      **从未登录过**
gopher                                     **从未登录过**
ftp                                        **从未登录过**
nobody                                     **从未登录过**
vcsa                                       **从未登录过**
saslauth                                   **从未登录过**
postfix                                    **从未登录过**
sshd                                       **从未登录过**
ntp                                        **从未登录过**
cxf              pts/2    127.0.0.1        一 4月 23 09:37:58 +0800 2018
ok                                         **从未登录过**
joe              tty1                      六 4月 14 19:33:41 +0800 2018
dbus                                       **从未登录过**
notepad                                    **从未登录过**
ett                                        **从未登录过**
test                                       **从未登录过**
chu              pts/2    172.16.2.100     一 5月 21 02:57:47 +0800 2018
test2                                      **从未登录过**

w、who、last、lastbon、lastlog显示登录命令用法

标签:apr   忽略   mes   who   highlight   ftp   pac   tor   test   

原文地址:https://www.cnblogs.com/joechu/p/9093891.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!