Linux系统下的用户审计方法
发布时间:2015-08-10 17:24:15 作者:佚名
我要评论
这篇文章主要介绍了Linux系统下的用户审计方法,包括基本的命令和一个记录用户行为的实例,需要的朋友可以参考下
创建审计日志目录
复制代码
代码如下:mkdir -p /var/log/user_audit
创建用户审计日志文件;
复制代码
代码如下:touch /var/log/user_audit/user_audit.log
将文件赋予低权限用户
复制代码
代码如下:chown nobody:nobody /var/log/user_audit/user_audit.log
赋予所有人写权限
复制代码
代码如下:chmod 002 /var/log/user_audit/user_audit.log
赋予所有用户追加权限
复制代码
代码如下:chattr +a /var/log/user_audit.log
编辑/etc/profile 增加以下内容;
复制代码
代码如下:export HISTORY_FILE=/var/log/user_audit/user_audit.log
export PROMPT_COMMAND='{ date "+%y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}")
export PROMPT_COMMAND='{ date "+%y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}")
实例
多人共同使用的服务器权限确实不好管理,误操作等造成故障,无法追究,最好的办法就是将用户操作实时记录到日志,并推送到远程日志服务器上。包括(用户登陆时间,目录,操作命令及时间戳等)。以便事后追查。
环境:centos5.5 X86_64 2台 #备注:把两台主机的防火墙和selinux关闭。在进行操作。
(一)日志服务器IP:10.0.2.164
(二)客户端服务器IP:10.0.2.165
1.先在日志服务器10.0.2.164主机上操作:
复制代码
代码如下:[root@MySQL-B ~]# echo "*.info /var/log/client" >> /etc/syslog.conf
#配置日志保存文件,把该文件第一行的*.info 提出来。单独放一行。
[root@MySQL-B ~]# service syslog restart #重启syslog日志服务。
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
[root@MySQL-B ~]# vim /etc/sysconfig/syslog #接收客户端写入。
#配置日志保存文件,把该文件第一行的*.info 提出来。单独放一行。
[root@MySQL-B ~]# service syslog restart #重启syslog日志服务。
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
[root@MySQL-B ~]# vim /etc/sysconfig/syslog #接收客户端写入。
把SYSLOGD_OPTIONS="-m 0" 更改为:SYSLOGD_OPTIONS="-m 1 -r"
2.然后在客户端服务器10.0.2.165主机上操作:
复制代码
代码如下:[root@MySQL-A ~]# vim /etc/profile #添加如下行。
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
[root@MySQL-A ~]# source /etc/profile #重新手动source更新。
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
[root@MySQL-A ~]# source /etc/profile #重新手动source更新。
2.1.客户机修改日志服务器10.0.2.165主机上操作:
复制代码
代码如下:[root@MySQL-A ~]# echo "10.0.2.164 logserver" >> /etc/hosts #日志服务器地址。
[root@MySQL-A ~]# echo "*.info @logserver" >> /etc/syslog.conf
#将info日志推送到日志服务器,把该文件第一行的*.info 提出来。单独放一行。
[root@MySQL-A ~]# /etc/init.d/syslog restart #重启syslog日志。
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
[root@MySQL-A ~]# echo "*.info @logserver" >> /etc/syslog.conf
#将info日志推送到日志服务器,把该文件第一行的*.info 提出来。单独放一行。
[root@MySQL-A ~]# /etc/init.d/syslog restart #重启syslog日志。
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
3.测试,在客户端主机上10.0.2.165主机上测试并操作:
复制代码
代码如下:[root@MySQL-A ~]# test
[root@MySQL-A ~]# echo "this is a test 1"
this is a test 1
[root@MySQL-A ~]# echo "this is a test 2"
this is a test 2
[root@MySQL-A ~]# echo "this is a test 3"
this is a test 3
[root@MySQL-A ~]# echo "this is a test 4"
this is a test 4
[root@MySQL-A ~]# echo "this is a test 5"
this is a test 5
[root@MySQL-A ~]# echo "this is a test 1"
this is a test 1
[root@MySQL-A ~]# echo "this is a test 2"
this is a test 2
[root@MySQL-A ~]# echo "this is a test 3"
this is a test 3
[root@MySQL-A ~]# echo "this is a test 4"
this is a test 4
[root@MySQL-A ~]# echo "this is a test 5"
this is a test 5
4.返回日志服务器10.0.2.164主机上看结果,是否记录下来客户端主机执行的操作?
复制代码
代码如下:[root@MySQL-B ~]# cat /var/log/client
Apr 6 10:37:55 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test1"
Apr 6 10:37:59 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test2"
Apr 6 10:38:01 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test3"
Apr 6 10:38:04 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test4"
Apr 6 10:38:06 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test5"
Apr 6 10:37:55 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test1"
Apr 6 10:37:59 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test2"
Apr 6 10:38:01 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test3"
Apr 6 10:38:04 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test4"
Apr 6 10:38:06 10.0.2.165 root: [euid=root]:root pts/1 Apr 6 10:37 (10.0.2.188):[/root]echo "this is a test5"
返回参数分别为:#操作时间 #操作IP #有效用户 #实际登陆时间 #路径 #使用的命令
相关文章

集成系统级Claw模式! Deepin 官宣发布 25.1 版本
deepin操作系统发布了最新的 25.1 版本更新,该版本基于 deepin 25 正式版积累的多轮内测成果,在 AI 能力、内核版本、桌面环境、文件管理器以及系统安全等方面进行了更新2026-04-13
又一代老硬件退场! Linux 内核正式放弃Intel 486 CPU
在过去的几十年间,CPU 的架构已经经历了飞速发展,x86 系列就是其中之一,而 i486 则属于该系列中的一个,当前,i486 的CPU处理器已经够老,从 Linux 7.1 开始将不再有对2026-04-09
我把 Linux 中最常用、最实用、最常被问到的命令按照实际使用场景分类整理,方便你快速查阅和记忆,内容覆盖日常运维、开发调试、性能分析、文件处理、网络、安全、系统管2026-04-08
一分钟内检查Linux服务器性能? 9个性能检测常用的基本命令
今天我们来看看Linux系统中用于性能监控的一系列命令,这些命令可以快速查看机器的负载情况,详细请看下文介绍2026-03-18
Linux作为操作系统领域灵活性和可定制性的基石,提供了大量满足不同用户需求的发行版,今天分享适合高级用户的15款Linux发行版2026-03-10
开箱即用? 这4个高手级Linux发行版远没你想象的那么安全易用
如果你正在纠结用哪个发行版?零基础新手别被“高端”“极客”“声明式”这些词冲昏头脑,先用好用的,再慢慢进阶2026-03-10
这几款SSH工具真的够用了! Linux好用的ssh工具推荐
在Linux上使用SSH,您需要安装一个SSH客户端,今天整理找到的8 款 SSH / 终端工具,从免费开源到企业级商用,从轻量化命令行到一站式工具箱,每款都做了介绍与对比,希望能2026-03-09
在Linux系统下有两种用户,即高级用户root,普通用户,高级用户root可以在系统中做任何事情,普通用户仅可在Linux系统中做有限的事情,下面我们就来看看切换方法2026-02-28
揭秘当前登录用户的身份! Linux中使用logname命令的技巧
logname命令就是这样一个简单但强大的工具,它能帮助我们轻松获取当前登录用户的用户名,今天,我们就来深入探索一下这个命令的工作原理、使用方法和最佳实践2026-02-26
在 Linux 系统中,DNS 缓存是一种将域名和 IP 地址映射关系缓存在本地的机制,可以加快域名解析速度,并减轻 DNS 服务器的负载2026-02-26




最新评论