The method of logging all user operations logs on time by login IP (with script)

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!

At the end of the/etc/profile configuration file to add the following script code can be implemented, the following script is my online search, the original author does not know. But the original script time variable has the error, cannot record the time, I test discovers and examines the revision:

ps1= "' WhoAmI ' @ ' hostname ':" ' [$PWD] ' historyuser_ip= ' who-u am I 2>/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 300/tmp/history/${logname}fiexport histsize=4096dt= ' date + '%y%m%d_%h%m%s ' ' Export HISTFILE= '/tmp/ HISTORY/${LOGNAME}/${USER_IP} history. $DT "Chmod 600/tmp/history/${logname}/*history* 2>/dev/null

From 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 logged-in system of users and IP address, which is a way to monitor the system security.

The method of logging all user operations logs on time by login IP (with script)

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.