ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux操作系统登录留痕功能

Linux操作系统登录留痕功能

原创 Linux操作系统 作者:zhcunique 时间:2021-02-18 09:57:07 0 删除 编辑

1. 在/etc/profile 文件末尾添加如下内容

history

RQ=`date "+%Y%m%d"`

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/record ]

then

mkdir /tmp/record

mkdir /tmp/record /achieve

chmod 777 /tmp/record

fi

export HISTSIZE=8192

SJ=`date "+%H:%M:%S"`

export HISTFILE="/tmp/record/${USER_IP}@${LOGNAME}.$SJ"

chmod 600 /tmp/record/${LOGNAME}/*record* 2>/dev/null

2. 使profile文件立即生效

source /etc/profile

3. 每次登陆操作退出shell后会在/tmp/record路径下产生一个新文件,文件名包含操作者信息,文件内容为执行的命令。


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69994536/viewspace-2757428/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
先后就职于银行、券商等金融机构科技部门,从事数据库管理、自动化运维管理与系统运维相关工作,拥有Oracle 11g OCM/OCP证书,通过CFA二级考试。

注册时间:2021-02-04

  • 博文量
    73
  • 访问量
    499682