For Linux user operation records, the command history is generally used to view historical records. However, if important data is deleted due to misoperations, The history Command will not be useful. So how should we implement the historical operation records? In fact, we can log on to the IP address to record the historical operations of all user logon operations! The specific operation is to add the following script code at the end of the/etc/profile configuration file: # HistoryUSER ='
For Linux user operation records, the command history is generally used to view historical records. However, if important data is deleted due to misoperations, The history Command will not be useful. So how should we implement the historical operation records? In fact, we can log on to the IP address to record the historical operations of all user logon operations! The specific operation is to add the following script code at the end of the/etc/profile configuration file:
# History
USER = 'whoam'
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/usr/local/history]; then
Mkdir/usr/local/history
Chmod 777/usr/local/history
Fi
If [! -D/usr/local/history/$ {LOGNAME}]; then
Mkdir/usr/local/history/$ {LOGNAME}
Chmod 300/usr/local/history/$ {LOGNAME}
Fi
Export HISTSIZE = 10000
DT = 'date + "% Y-% m-% d _ % H: % M: % S "'
Export HISTFILE = "/usr/local/history/$ {LOGNAME}/$ {USER }@$ {USER_IP} _ history. $ DT"
Chmod 600/usr/local/history/$ {LOGNAME}/* history * 2>/dev/null
[Root @ server ~] # Source/etc/profile
[Root @ server ~] # Logout
# Log out of the system and log on again. The logs are recorded in the/usr/local/history/directory.
[Root @ server ~] # Ll/usr/local/history/root/
Total usage 12
-Rw ------- 1 root 77 October 11 09:09 root@192.168.1.23_history.2012-10-11_09: 09: 12
-Rw ------- 1 root 529 October 11 09:11 root@192.168.1.23_history.2012-10-11_09: 09: 16
-Rw ------- 1 root 187 October 11 09:12 root@192.168.1.23_history.2012-10-11_09: 11: 26