手机版
你好,游客 登录 注册
背景:
阅读新闻

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

[日期:2012-10-11] 来源:Linux社区  作者:300second [字体:大 中 小]

对于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" = "" ]; then
 USER_IP=`hostname`
fi

if [ ! -d /tmp/history ]; then
 mkdir /tmp/history
 chmod 777 /tmp/history
fi

if [ ! -d /tmp/history/${LOGNAME} ]; then
 mkdir /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

linux
相关资讯       Linux日志  history 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款