centos6 用户登陆管理

  • 查看当前登陆有哪些用户,在做什么
[root@web01 ~]# w
 14:48:52 up  5:21,  3 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/1    192.168.127.1    14:46    0.00s  0.00s  0.00s w
root     tty1     -                14:46    1:50   0.00s  0.00s -bash
root     pts/0    192.168.127.1    11:49    2:30   0.04s  0.04s -bash
#######tty1表示本地登陆pts/0和pts/1表示ssh远程登陆#######
  • 查看用户登陆记录
[root@web01 ~]# last
root     tty1                          Tue May 29 14:54   still logged in   
root     tty1                          Tue May 29 14:46 - 14:52  (00:05)    
root     pts/1        192.168.127.1    Tue May 29 14:46 - 14:53  (00:07)    
root     pts/1        192.168.127.1    Tue May 29 14:02 - 14:07  (00:05)    
root     pts/0        192.168.127.1    Tue May 29 11:49   still logged in 
[root@web01 ~]# last test200    #查看某一个用户的登陆记录
test200  pts/1        192.168.127.1    Tue May 29 14:57   still logged in   

wtmp begins Sun Apr 29 19:37:20 2018
  • 登陆用户在线交流
[root@web01 ~]# write root
write: root is logged in more than once; writing to pts/1

hello

[root@web01 ~]# 
Message from [email protected] on pts/0 at 15:14 ...

hello
EOF
  • 将用户踢出登陆(较危险)
[root@web01 ~]# w
 15:04:54 up  5:37,  2 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     tty1     -                14:54   10:21   0.00s  0.00s -bash
root     pts/0    192.168.127.1    11:49    0.00s  0.05s  0.00s w
[root@web01 ~]# pkill -kill -t tty1
[root@web01 ~]# w
 15:05:15 up  5:37,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.127.1    11:49    0.00s  0.05s  0.00s w

  • 记录用户登陆信息的文件

  1、/var/run/utmp:记录当前正在登陆系统的用户信息,默认有who和w记录当前登陆用户的信息,uptime记录系统启动时间;

  2、/var/log/wtmp:记录当前正在登陆和历史登陆系统的用户信息,默认有last命令查看;

  3、/var/log/btmp:记录失败的登陆尝试信息,默认由lastb命令查看;

  ####################如果需要清除用户登陆信息,直接清空这几个文件就行了################

猜你喜欢

转载自www.cnblogs.com/suffergtf/p/9105260.html