Use scripts to log all user actions under Linux

Source: Internet
Author: User
Tags chmod mkdir

This script is found on the internet, a little bit of modification, can be implemented under Linux all users, whether remote or local landing, all operations on this machine will be recorded, and generate a "user/ip/time" files stored in the specified location, Convenient for the administrator to see what different users are doing on the server!

At present, this code only implements the record user's Operation command, but like VI Edit will only record VI this command, but in the document modified content cannot record ... Have time to study again!

Append the following code to the/etc/profile file

ps1= "' WhoAmI ' @ ' hostname ':" ' [$PWD] '
history
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/tmp/history]
then
mkdir/tmp/history
chmod 777/tmp/history
fi
if [!-d/tmp/history/${ LOGNAME}]
then
mkdir/tmp/history/${logname}
chmod 300/tmp/history/${logname}
fi
export histsize=4096
dt= ' 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

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

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.