黑松山资源网 Design By www.paidiu.com
对于Linux用户操作记录一般通过命令history来查看历史记录,但是如果在由于误操作而删除了重要的数据的情况下,history命令就不会有什么作用了。那么依然要存有历史操作记录应该如何来实现呢?
其实我们可以通过登陆IP地址来记录所有用户登录所操作的历史操作!具体操作就是在/etc/profile配置文件的末尾加入以下脚本代码来实现:
复制代码代码如下:
[root@server ~]# cat /etc/profile<< EOF
>
> history
>
> USER=`whoami`
>
> USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
>
> if [ "$USER_IP" = "" ]; then
> USER_IP=`hostname`
> fi
>
> if [ ! -d /tmp/history ]; then
> mkdir /tmp/history
> chmod 777 /tmp/history
> fi
>
> if [ ! -d /tmp/history/${LOGNAME} ]; then
> mkdir /tmp/history/${LOGNAME}
> chmod 300 /tmp/history/${LOGNAME}
> fi
>
> export HISTSIZE=4096
>
> DT=`date +"%Y-%m-%d_%H:%M:%S"`
>
> export HISTFILE="/tmp/history/${LOGNAME}/${USER}@${USER_IP}_history.$DT"
>
> chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null
>
> EOF
[root@server ~]# source /etc/profile
[root@server ~]# logout
# 此时需要退出系统再重新登录,在/tmp/history/目录下才有记录
通过上面的脚本代码可以看出来,在系统的/tmp下就新建了个history目录(这个目录可以自定义),在目录中记录了所有的登陆过系统的用户和IP地址,这也是监测系统安全的方法之一。在进行一系列的操作之后,我们进入/tmp/history目录查看历史记录:
复制代码代码如下:
[root@server ~]# cd /tmp
[root@server tmp]# ll
总计 24
drwx------ 2 root root 4096 2012-10-11 gconfd-root
drwxrwxrwx 3 root root 4096 2012-10-11 history
drwx------ 2 root root 4096 08-11 01:11 keyring-Ki8IOJ
srwxr-xr-x 1 root root 0 2012-10-11 mapping-root
srw------- 1 root root 0 2012-10-11 scim-panel-socket:0-root
drwx------ 2 root root 4096 2012-10-11 ssh-jPPigl3182
drwx------ 2 root root 4096 10-10 21:16 ssh-KDmPtr3350
[root@server tmp]# cd history/
[root@server history]# ll
总计 4
d-wx------ 2 root root 4096 10-10 21:16 root
[root@server history]# cd root/
[root@server root]# ll
总计 4
-rw------- 1 root root 37 10-10 21:16 root@192.168.1.96_history.2012-10-10_21:16:42
其实我们可以通过登陆IP地址来记录所有用户登录所操作的历史操作!具体操作就是在/etc/profile配置文件的末尾加入以下脚本代码来实现:
复制代码代码如下:
[root@server ~]# cat /etc/profile<< EOF
>
> history
>
> USER=`whoami`
>
> USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
>
> if [ "$USER_IP" = "" ]; then
> USER_IP=`hostname`
> fi
>
> if [ ! -d /tmp/history ]; then
> mkdir /tmp/history
> chmod 777 /tmp/history
> fi
>
> if [ ! -d /tmp/history/${LOGNAME} ]; then
> mkdir /tmp/history/${LOGNAME}
> chmod 300 /tmp/history/${LOGNAME}
> fi
>
> export HISTSIZE=4096
>
> DT=`date +"%Y-%m-%d_%H:%M:%S"`
>
> export HISTFILE="/tmp/history/${LOGNAME}/${USER}@${USER_IP}_history.$DT"
>
> chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null
>
> EOF
[root@server ~]# source /etc/profile
[root@server ~]# logout
# 此时需要退出系统再重新登录,在/tmp/history/目录下才有记录
通过上面的脚本代码可以看出来,在系统的/tmp下就新建了个history目录(这个目录可以自定义),在目录中记录了所有的登陆过系统的用户和IP地址,这也是监测系统安全的方法之一。在进行一系列的操作之后,我们进入/tmp/history目录查看历史记录:
复制代码代码如下:
[root@server ~]# cd /tmp
[root@server tmp]# ll
总计 24
drwx------ 2 root root 4096 2012-10-11 gconfd-root
drwxrwxrwx 3 root root 4096 2012-10-11 history
drwx------ 2 root root 4096 08-11 01:11 keyring-Ki8IOJ
srwxr-xr-x 1 root root 0 2012-10-11 mapping-root
srw------- 1 root root 0 2012-10-11 scim-panel-socket:0-root
drwx------ 2 root root 4096 2012-10-11 ssh-jPPigl3182
drwx------ 2 root root 4096 10-10 21:16 ssh-KDmPtr3350
[root@server tmp]# cd history/
[root@server history]# ll
总计 4
d-wx------ 2 root root 4096 10-10 21:16 root
[root@server history]# cd root/
[root@server root]# ll
总计 4
-rw------- 1 root root 37 10-10 21:16 root@192.168.1.96_history.2012-10-10_21:16:42
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年10月10日
2024年10月10日
- 邰肇玫.1981-雪歌(滚石25周年经典复刻系列)【滚石】【WAV+CUE】
- 《Duck Side of the Moon》特色玩法介绍
- 《刀郎 辉煌10年绝版珍藏 3CD》[WAV/分轨][1.6GB]
- 《张韶涵 全面沦陷》[WAV/分轨][370MB]
- 《极品汽车音乐 三十而立 一起走过的岁月 2CD》[WAV/分轨][990MB]
- 周冰倩1997-珍藏精选-真的好想你[WAV+CUE]
- 许廷铿2017《THEULTIMATECOLLECTION》2CD[星梦娱乐][WAV+CUE]
- 徐小明1983-再向虎山行(LP版)[文志][WAV+CUE]
- 《黑神话:悟空》石双双COS热潮持续升温 丝袜你喜欢么
- Qiddiya IRL游戏之旅在东京电玩展重磅登场
- 北京首家任天堂Switch体验店开业:国行机立减200元
- 张秀卿.1999-赢【神采】【WAV+CUE】
- 群星.1977-多多宝丽多(LP版)【宝丽金】【WAV+CUE】
- 刘德华.1989-永远...记得你(2012金碟复刻版)【EMI百代】【WAV+CUE】
- 《维纳斯璀璨假期死或生Xtreme》游戏特色玩法