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