Linux系统命令审计

命令审计

1、 创建审计日志文件存放目录:

[root@Centos-1 ~]# mkdir -p /tmp/logs/host_log

2、 更改目录权限使其可写、防删除:

[root@Centos-1 ~]# chmod 777 /tmp/logs/host_log

[root@Centos-1 ~]# chmod +t /tmp/logs/host_log

3、 编辑/etc/profile,在文件最后增加如下:

[root@Centos-1 ~]# vim /etc/profile
#命令审计
if [ ! -d  /tmp/logs/host_log/${LOGNAME} ]
then
    mkdir -p /tmp/logs/host_log/${LOGNAME}
    chattr +a    #时该文件内容只可追加 /tmp/logs/host_log/${LOGNAME}
fi

export HISTORY_FILE="/tmp/logs/host_log/${LOGNAME}/commond_history.log"

export PROMPT_COMMAND='{ date "+%Y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}") #### $(history 1 | { read x cmd; echo "$cmd"; })"; } >>$HISTORY_FILE'

4、 查看效果:

[root@Centos-1 ~]# ls /tmp/logs/host_log/
root
[root@Centos-1 ~]# ls /tmp/logs/host_log/root/
commond_history.log
[root@Centos-1 ~]# cat /tmp/logs/host_log/root/commond_history.log
2017-09-27 13:14:22 ##### root pts/1 (192.168.15.253) #### ipvsadm -e -t 192.168.14.13:80 -r 192.168.14.127 -w 0
2017-09-27 13:14:27 ##### root pts/1 (192.168.15.253) #### ls
2017-09-27 13:14:56 ##### root pts/1 (192.168.15.253) #### w
2017-09-27 13:15:31 ##### root pts/1 (192.168.15.253) #### pwd
2017-09-27 13:15:35 ##### root pts/1 (192.168.15.253) #### ls

[root@Centos-1 ~]# rm -f /tmp/logs/host_log/root/commond_history.log
rm: 无法删除"/tmp/logs/host_log/root/commond_history.log": 不允许的操作

转载于:https://my.oschina.net/adailinux/blog/1544099

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值