当前位置:网站首页>The history command adds time to the history
The history command adds time to the history
2022-07-24 06:32:00 【Step on the path of the pit】
Linux Under the system, it can pass history Command to view all the historical operation records of the user , But by default ,history The command can only view the user's historical operation records , It doesn't distinguish between users and operation time , It is not convenient for audit analysis .
Of course , Some bad operating habits may also leak sensitive information through command history .
Add time to command history
By setting export HISTTIMEFORMAT=’\%F \%T ‘, Bring command execution time to history .
This configuration can be written in /etc/profile in , Of course, if you want to configure the specified user , This configuration can be written in /home/\$USER/.bash_profile in .
unset i
unset -f pathmunge
export HISTTIMEFORMAT='%F %T 'For the configuration to take effect immediately, execute source /etc/profile, Check it again history Record , You can see the command execution time in the record .
1012 2021-03-22 13:59:10 vim /etc/profile
1013 2021-03-22 13:59:18 source /etc/profile
1014 2021-03-22 13:59:22 historyIf you want to achieve more detailed records , For example, users who have logged into the system 、IP Address 、 Operation command and operation time correspond one by one , It can be done by /etc/profile Add the following code to achieve .
export HISTTIMEFORMAT="%F %T `who -u 2>/dev/null | awk '{print $NF}'|sed 's/[()]//g'` `whoami` "modify /etc/profile And after loading ,history Record the following , Time 、IP、 The users and the commands they execute all correspond one by one
1042 2021-03-22 14:20:39 124.193.98.180 root vim /etc/profile
1043 2021-03-22 14:20:52 124.193.98.180 root source /etc/profile
1044 2021-03-22 14:20:53 124.193.98.180 root historyThrough the above configuration , We can basically meet the daily audit work , But it should be easy for people who know the system to see , This method just sets the environment variables , The attacker unset Drop this environment variable , Or just delete the command history , For safety emergency , This is undoubtedly a disaster .
In response to such questions , We should revise it bash Source code , Give Way history The record passed syslog Send to remote logserver in , Greatly increased the attacker's ability to history The difficulty of recording integrity damage .
边栏推荐
猜你喜欢

Jenkins自动化无人值守运行(上/下)

Summary of common working methods (7S, SWOT analysis, PDCA cycle, smart principle, 6w2h, time management, WBS, 28 principles)

第二周作业

Heap overflow of kernel PWN basic tutorial

How to build a website full of ritual sense and publish it on the public website 2-2

Log collection and analysis platform

【217】#!/ The meaning of usr/bin/env
![[226] instructions for Wireshark parameters](/img/47/0d3fd221695920e02b1f690a2a21c1.png)
[226] instructions for Wireshark parameters

IP class notes (4)
![[222] memory overflow and location](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[222] memory overflow and location
随机推荐
Modeling of XML
服务器硬件及RAID配置实战
IP lesson summary (3)
LuckyFrameWeb测试平台(一款支持接口自动化、WEB UI自动化、APP自动化,并且支持分布式测试的全纬度免费开源测试平台)
JSP tag 02
Install Apache manually
Remember to get the password of college student account once, from scratch
【214】什么是自动化框架
[no need for public IP] configure a fixed public TCP port address for remote desktop raspberry pie
Flink production environment configuration recommendations
Interview questions for Test Manager / test team leader / Test Supervisor
Leetcode sword finger offer jz25 merges two sorted linked lists
IP job (6)
[218] what are the advantages and disadvantages of CS architecture and BS architecture and data on the server and client?
leetcode剑指offer jz5 替换空格字符串
Custom MVC 1.0
RAID5 and LVM are used in combination
Remote connection to Qunhui NAS at home [no public IP, free intranet penetration]
CentOS操作系统安全加固
Summary of common working methods (7S, SWOT analysis, PDCA cycle, smart principle, 6w2h, time management, WBS, 28 principles)