CentOS查询用户登录日志

2015-12-28 22:24:59 7177

1.查看日志文件

 Linux查看/var/log/wtmp文件查看可疑IP登陆

 last -f /var/log/wtmp

     

    该日志文件永久记录每个用户登录、注销及系统的启动、停机的事件。因此随着系统正常运行时间的增加,该文件的大小也会越来越大,增加的速度取决于系统用户登录的次数。该日志文件可以用来查看用户的登录记录,last命令就通过访问这个文件获得这些信息,并以反序从后向前显示用户的登录记录,last也能根据用户、终端tty或时间显示相应的记录。 

2.查看/var/log/secure文件寻找可疑IP登陆次数

     

3.查看其他用户的操作命令

(1)通过在/etc/profile里面加入以下代码就可以实现:

#cheke history command start!

PS1="`whoami`@`hostname`:"[$PWD]

history

USER_IP=`who -u am i 2>/dev/null| awk {print $NF}|sed -e s/[()]//g`

if [ "$USER_IP" = "" ]

then

USER_IP=`hostname`

fi

if [ ! -d /tmp/historycommand ]

then

mkdir /tmp/historycommand

chmod 777 /tmp/historycommand

fi

if [ ! -d /tmp/historycommand/${LOGNAME} ]

then

mkdir /tmp/historycommand/${LOGNAME}

chmod 300 /tmp/historycommand/${LOGNAME}

fi

export HISTSIZE=4096

DT=`date "+%Y-%m-%d_%H:%M:%S"`

export HISTFILE="/tmp/historycommand/${LOGNAME}/${USER_IP} historycommand.$DT"

chmod 600 /tmp/historycommand/${LOGNAME}/*historycommand* 2>/dev/null

#the end

(2)source /etc/profile 使用脚本生效

(3)上面脚本在系统的/tmp新建个historycommand目录,记录所有登陆过系统的用户和IP地址(文件名),每当用户登录/退出会创建相应的文件,该文件保存这段用户登录时期内操作历史,可以用这个方法来监测系统的安全性。

    

提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: