首页 > 系统相关 >linux(centos 6/7/8,kylin)下记录所有用户的操作以及ip、时间

linux(centos 6/7/8,kylin)下记录所有用户的操作以及ip、时间

时间:2022-12-10 16:33:20浏览次数:46  
标签:kylin log centos ip LOGNAME USER var root history

[root@sdw ~]# mkdir /var/log/history
[root@sdw ~]# chmod 777 /var/log/history

编辑/etc/profile文件,在文件末尾加入下面代码:

[root@iZ23nn1p4mjZ root]# vi /etc/profile

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 /var/log/history ]; then
mkdir /var/log/history
chmod 777 /var/log/history
fi
if [ ! -d /var/log/history/${LOGNAME} ]; then
mkdir /var/log/history/${LOGNAME}
chmod 300 /var/log/history/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +"%Y%m%d_%H:%M:%S"`
export HISTFILE="/var/log/history/${LOGNAME}/${USER}@${USER_IP}_$DT"
chmod 600 /var/log/history/${LOGNAME}/*history* 2>/dev/null

注释: /var/log/history这是记录日志的存放位置,可以自定义。
在/var/log/history下会以每个用户为名新建一个文件夹

[root@iZ23nn1p4mjZ history]# ll
total 4
d-wx------ 2 root root 4096 Jan 9 07:29 root

[root@iZ23nn1p4mjZ root]# ll
total 4
-rw------- 1 root root 54 Jan 9 07:29 [email protected]_20170109_07:29:05



标签:kylin,log,centos,ip,LOGNAME,USER,var,root,history
From: https://blog.51cto.com/zhjh256/5927790

相关文章

  • CentOS 7.6 bond mode4 配置
    双网卡配置bondmode4配置1#cat/etc/redhat-release2CentOSLinuxrelease7.6.1810(Core)yumsearchifconfigyuminstallnet-tools.x86_64查看网线是......
  • LVM-VDO使用(官方手册,针对centos8或redhat8)
    官方参考文档https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/8/html/deduplicating_and_compressing_logical_volumes_on_rhel/index参考官方......
  • Pushing the Limits of Simple Pipelines for Few-Shot Learning: External Data and
    论文:https://hushell.github.io/pmf/本论文探究了以下问题:1.对外部数据进行预训练如何有利于FSL。2.如何利用最先进的transform架构。3.微调如何减轻domainshift。两......
  • post表单数据格式完全解析multipart/form-data(C#实现)
    post表单数据格式完全解析multipart/form-data参数说明内容boundaryboundary一个字符串,用以分隔不同的参数;stringboundary=Guid.NewGuid().ToString()......
  • snipaste用法
    Snipaste基本使用快捷键开始截图:F1保存到剪切板:Ctrl+C保存到文件:Ctrl+S取消当前截图:Esc回放截图记录:进入截图后,按“,”或“.”启动放大镜:Alt......
  • 环形队列、 条带环形队列 Striped-RingBuffer (史上最全)
    文章很长,而且持续更新,建议收藏起来,慢慢读!疯狂创客圈总目录博客园版为您奉上珍贵的学习资源:免费赠送:《尼恩Java面试宝典》持续更新+史上最全+面试必备2000页+面......
  • 在ubuntu下 service iptables start启动iptables失败
    尝试通过执行serviceiptablesstart启动iptables失败,提示iptables:unrecognizedservice。可以通过modprobeip_tables启动。补充:1、service可以控制系统服务(打开、......
  • python使用指定源pip
    参数加一个 -ipipinstalllightgbm-ihttps://pypi.tuna.tsinghua.edu.cn/simple国内常用镜像源清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/阿里云:https://mir......
  • pip install uiautomation
    pipinstalluiautomationuispy下载1.下载UISPY 2.CMD指令导入uiautomation库pipinstalluiautomation-ixxx3.打开计算器,然后打开UISpy 如图ControlType为”Control......
  • Ubuntu2204设置固定IP地址
    前言Ubuntu每次升级都会修改一部分组件.从1804开始Ubuntu开始使用netplan的方式进行网络设置.但是不同版本的配置一直在升级与变化.今天掉进坑里折腾了好久.所以这边总结一......