Linux Logging Logon IP method

Source: Internet
Author: User

Ps:linux user operations records are generally viewed through the command history, but if the important data is deleted because someone mistakenly manipulated it, this situation does not work. The following methods can be implemented by logging the login IP address and all users log on the operation of logging!

The following script code can be implemented at the end of the/etc/profile configuration file , as can be seen from the above code, in the system's/tmp New History directory (this directory can be customized), All the users and IP addresses of the logged-in system are recorded in the directory, which is one of the methods to monitor the system security.

ps1="' whoami ' @ ' hostname ':"'[$PWD]'historyuser_ip=`W.H.O.-U am I2>/dev/NULL|awk '{print $NF}'|sed-E's/[()]//g'`if["$USER _ip"="" ] Thenuser_ip=`hostname`fiif[!-d/tmp/History ] Thenmkdir/tmp/ Historychmod 777/tmp/ Historyfiif[!-d/tmp/history/${logname}] Thenmkdir/tmp/history/${logname}chmod  -/tmp/history/${logname}fiExport Histsize=4096DT=`Date+"%y%m%d_%h%m%s"' Export Histfile="/tmp/history/${logname}/${user_ip} history. $DT"chmod  -/tmp/history/${logname}/*history* 2>/dev/null through the above code can be seen in the system/TMP to create a new history directory (this directory can be customized), in the directory to record all the users and IP addresses logged in the system, which is one of the methods to monitor the system security. 

Linux Logging Logon IP method

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.