位置: 编程技术 - 正文

通过登陆IP记录Linux所有用户登录所操作日志的方法(登录ip怎么查位置)

编辑:rootadmin
对于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 /tmp/history > fi > > if [ ! -d /tmp/history/${LOGNAME} ]; then > mkdir /tmp/history/${LOGNAME} > chmod /tmp/history/${LOGNAME} > fi > > export HISTSIZE= > > DT=`date +"%Y-%m-%d_%H:%M:%S"` > > export HISTFILE="/tmp/history/${LOGNAME}/${USER}@${USER_IP}_history.$DT" > > chmod /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 总计 drwx------ 2 root root -- gconfd-root drwxrwxrwx 3 root root -- history drwx------ 2 root root - : keyring-Ki8IOJ srwxr-xr-x 1 root root 0 -- mapping-root srw------- 1 root root 0 -- scim-panel-socket:0-root drwx------ 2 root root -- ssh-jPPigl drwx------ 2 root root - : ssh-KDmPtr [root@server tmp]# cd history/ [root@server history]# ll 总计 4 d-wx------ 2 root root - : root [root@server history]# cd root/ [root@server root]# ll 总计 4 -rw------- 1 root root - : root@..1._history.--_::

推荐整理分享通过登陆IP记录Linux所有用户登录所操作日志的方法(登录ip怎么查位置),希望有所帮助,仅作参考,欢迎阅读内容。

通过登陆IP记录Linux所有用户登录所操作日志的方法(登录ip怎么查位置)

文章相关热门搜索词:查看登录ip,记录登录ip,知道登录的ip地址能找到人吗,登录ip怎么看,记录登录ip,通过登录ip查地址,知道登录的ip地址能找到人吗,如何查看登录记录ip,内容如对您有帮助,希望把文章链接给更多的朋友!

Ubuntu .解决重启后resolv.conf清空的问题 这跟以前用RHT系的情况是完全不一样的:在google上搜了一下,发现这里面还真有些奥妙:1/etc/resolv.conf其实是一个Link它其实指向的是/run/resolvconf/resolv.conf2

redhat linux enterprise 5 输入ifconfig无效的解决方法 如果我们输入/sbin/ifconfig或/usr/bin/gcc就可以执行命令行。为了不输入命令行的完整路径,最好给用户配置好路径。vi~/.bash_profile里,添加PATH=$PATH:/sbin回车

linux使用su切换用户提示 Authentication failure的解决方法 这个问题产生的原因是由于ubtun系统默认是没有激活root用户的,需要我们手工进行操作,在命令行界面下,或者在终端中输入如下命令:sudopasswdPassword

本文链接地址:https://www.jiuchutong.com/biancheng/363196.html 转载请保留说明!

上一篇:Linux命令(shell)从入门到精通 学习笔记之2 使用find和xargs (linux shell怎么用)

下一篇:Ubuntu 12.04解决重启后resolv.conf清空的问题(ubuntu 重启xorg)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络