Linux System when you enter and execute commands in the shell (console), the shell automatically logs your commands to the history list, which is typically saved in the. bash_history file in the user directory. By default,historydoes not log the execution time of the command, and if you want to record which user executed some of the commands, we need to modify the/etc/profile file to implement
First, the history shows that the user name and command execution time is relatively simple, as long as the /etc/profile file is appended
Export histtimeformat= "%F%T ' WhoAmI '"
If you want to display the login IP, you need to obtain the source login IP First:
user_ip= ' who-u am I 2>/dev/null| awk ' {print $NF} ' |sed-e ' s/[()]//g "
If ["$USER _ip" = ""]
Then
User_ip= ' hostname '
Fi
then the user_ip Write Histtimeformat can
Export histtimeformat= "%F%T ' whoami ' $USER _ip"
Then Source/etc/profile ( takes effect immediately without having to log back in ) to perform the history | More
2014-12-08 10:05:09 root 192.168.10.136 history
1001 2014-12-08 10:14:24 root 192.168.10.136 cd root
1002 2014-12-08 10:14:27 root 192.168.10.136 ls
1003 2014-12-08 10:14:30 Root 192.168.10.136 cd/opt
Note: When the HISTTIMEFORMAT environment variable is set, the execution time is recorded by the newly executed bash commands , and the time of the command execution is not recorded until the Histtimeformat variable is set.
The Linux history command displays the user name and operation time