通过登陆IP记录Linux所有用户登录所操作的日志

对于Linux用户操作记录一般通过命令history来查看历史记录,但是如果在由于误操作而删除了重要的数据的情况下,history命令就不会有什么作用了。那么依然要存有历史操作记录应该如何来实现呢?

其实我们可以通过登陆IP地址来记录所有用户登录所操作的历史操作!具体操作就是在/etc/profile配置文件的末尾加入以下脚本代码来实现:

[root@server ~]# vi history.sh#!/bin/bash## ScriptName:history.sh# Description: fits CentOS 5.x and RHEL 5.x series# Version:1.0## Author:300second# QQ:84287030# Date:21:10 2012-10-10#cat >>/etc/profile<< EOF

history

USER=`whoami`

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

if [ “$USER_IP” = “” ]; thenUSER_IP=`hostname`fi

if [ ! -d /tmp/history ]; thenmkdir /tmp/historychmod 777 /tmp/historyfi

if [ ! -d /tmp/history/${LOGNAME} ]; thenmkdir /tmp/history/${LOGNAME}chmod 300 /tmp/history/${LOGNAME}fi

export HISTSIZE=4096

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

export HISTFILE=”/tmp/history/${LOGNAME}/${USER}@${USER_IP}_history.$DT”

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

EOF

source /etc/profile

,福报够的人,从来就没听到过是非。

通过登陆IP记录Linux所有用户登录所操作的日志

相关文章:

你感兴趣的文章:

标签云: