Linux uses Prompt_command to realize audit function

Source: Internet
Author: User


Command audit, using logger method to record information to/TMP, the directory can also be modified by their own

This is according to the user to classify, if it is not convenient also can use time to classify also line


This is only in the root user has the record, if wants all user to have the record, must add to/etc/profile inside

echo "Export prompt_command=" {msg=\$ (History 1 | {read x cmd; echo \ $cmd;}); user=\$ (WhoAmI); echo \$ (date \ "+%y-%m-%d%h:%m:%s\"): \ $user: \ ' pwd\ '/:\ $msg----\$ (who am I); } >>/tmp/\ ' hostname\ '. \ ' whoami\ '. History-timestamp ' ">>/root/.bash_profile


Mkdir-p/var/log/user_record/

echo "Export prompt_command=" {msg=\$ (History 1 | {read x cmd; echo \ $cmd;}); user=\$ (WhoAmI); echo \$ (date \ "+%y-%m-%d%h:%m:%s\"): \ $user: \ ' pwd\ '/:\ $msg----\$ (who am I); } >>/var/log/user_record/\ ' hostname\ '. \ ' whoami\ '. History-timestamp ' ">>/etc/profile


Or

Vim/etc/profileexport history_file=/var/log/history/${logname}/' Date ' +%y-%m-%d_%t '. Log &>/dev/null # Custom log file path and name Export prompt_command= ' {date + ' $ (Who am I-|awk "{print \$1\" \ "\$2\" \ "\$5}") $ (History 1 | {read x cmd; echo "$cmd";}) ";} >> $HISTORY _file ' &>/dev/null


A lot of methods can be based on their own needs to do concrete

Linux uses Prompt_command to realize audit function

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.