Logs of all Linux user logon operations are recorded through the logon IP address

Source: Internet
Author: User
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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.