Chinaunix首页 | 论坛 | 博客
  • 博客访问: 628295
  • 博文数量: 79
  • 博客积分: 2616
  • 博客等级: 少校
  • 技术积分: 1036
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-28 17:41
个人简介

苏北下邳附近人氏, 跟项羽、刘邦老乡,吕布很不幸,死在俺家门口那块小麦田上。 爱好家乡的小麦煎饼、盐豆子! 新浪微博:@dodolovely

文章分类

全部博文(79)

文章存档

2013年(2)

2012年(67)

2011年(1)

2010年(9)

分类: LINUX

2012-08-07 14:11:28

PS:Linux用户操作记录一般通过命令history来查看历史记录,但是如果因为某人误操作了删除了重要的数据,这种情况下history命令就不会有什么作用了。以下方法可以实现通过记录登陆IP地址和所有用户登录所操作的日志记录!

在/etc/profile配置文件的末尾加入以下脚本代码就可以实现,下面脚本是我网上找来的,原作者不知。但原脚本的时间变量有错误,不能记录时间,本人测试发现并检查修正:



  1. PS1="`whoami`@`hostname`:"'[$PWD]'
  2. history
  3. USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
  4. if [ "$USER_IP" = "" ]
  5. then
  6. USER_IP=`hostname`
  7. fi
  8. if [ ! -d /tmp/history ]
  9. then
  10. mkdir /tmp/history
  11. chmod 777 /tmp/history
  12. fi
  13. if [ ! -d /tmp/history/${LOGNAME} ]
  14. then
  15. mkdir /tmp/history/${LOGNAME}
  16. chmod 300 /tmp/history/${LOGNAME}
  17. fi
  18. export HISTSIZE=4096
  19. DT=`date +"%Y%m%d_%H%M%S"`
  20. export HISTFILE="/tmp/history/${LOGNAME}/${USER_IP} history.$DT"
  21. chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null

通过上面的代码可以看出来,在系统的/tmp新建个history目录(这个目录可以自定义),在目录中记录了所有的登陆过系统的用户和IP地址,这也是监测系统安全的方法之一。

脚本自动生成的记录文件如下:


本文来自: 
阅读(1335) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~