Linux利用script命令记录用户的服务器操作行为
1.在服务器上创建文件夹
[root@lw ~]# mkdir -p /opt/logs/scripts
2.授予权限, 目录需要其他用户有写的权限
[root@lw ~]# chmod -R 743 /opt/logs/scripts
3.在/etc/profile末尾添加如下内容
[root@lw ~]# cat /etc/profile
...
if [ $UID -ge 0 ] ; then
exec /usr/bin/script -t 2>/opt/logs/scripts/$USER-$UID-`date +%Y%m%d%H%M`.date -a -f -q /opt/logs/scripts/$USER-$UID-`date +%Y%m%d%H%M`.log
fi
4.查看、回放操作记录
[root@lw scripts]# ll
总用量 2924
-rw-rw-r-- 1 helpt helpt 390 10月 30 15:49 helpt-1005-201908301549.date
-rw-rw-r-- 1 helpt helpt 5784 10月 30 15:49 helpt-1005-201908301549.log
-rw-rw-r-- 1 lant lant 426 10月 30 14:37 lant-1004-201909301437.date
-rw-rw-r-- 1 lant lant 1022 10月 30 14:37 lant-1004-201909301437.log
-rwxr---wx 1 root root 35 10月 30 14:34 root-0-201909301434.date
-rwxr---wx 1 root root 145 10月 30 14:34 root-0-201909301434.log
[root@lw scripts]# scriptreplay helpt-1005-201908301549.date helpt-1005-201908301549.log