A bash configuration file that writes user-executed commands to a syslog under a Linux system

Source: Internet
Author: User
Tags syslog kali linux

Note that if the user's shell is/bin/sh, it needs to be modified to/bin/bash!! Usermod-s/bin/bash User Name

Kali Linux System corresponding configuration file is/ETC/BASH.BASHRC, different release version may be different

Step one: VI/ETC/BASHRC added as follows:

histfilesize=2000

histsize=2000

histtimeformat= "%y%m%d-%h%m%s:"

Export Histtimeformat

#export prompt_command= ' {command=$ (History 1 | {read x y; echo $y;}); Logger-p local1.notice-t bash-i "user= $USER, ppid= $PPID, from= $SSH _client,pwd= $PWD, command: $command"; }‘


Export prompt_command= ' {ip=$ (who-u am I | {Read x y z a b c D; Echo $d;}); command=$ (History 1 | {read x y; echo $y;}); Logger-p local1.notice-t bash-i "user= $USER, ppid= $PPID, from= $ip, pwd= $PWD, command: $command"; }‘

Step Two: Modify/etc/syslog.conf or/etc/rsyslog.conf to add Local1.notice @syslog host address or *. * @syslog host address. Restart the Syslog service

Step three: Exit the current shell and log in again.

The current achievable effect:

1. All instructions can be recorded regardless of errors or not. and contains the source IP (except local login), the current directory

2. All user commands that can be logged into bash can be recorded. and contains the source IP (except local login), the current directory


Two systems Redhat and CentOS are currently tested, with the following version information:

1.Read hat:red hat Enterprise Linux Server release 6.0 (Santiago)

Kernel: 2.6.32-71.el6.i686 bash version: GNU bash, version 4.1.2 (1)-release (I386-REDHAT-LINUX-GNU)

2.centos:centos Release 5.4 (Final) kernel: 2.6.18-164.el5 bash version: GNU bash, version 3.2.25 (1)-release (i686-redhat-linux- Gnu


Sample:

BASH[4463]: user=soc,ppid=4437,from=10.70.20.20 4763 22,pwd=/root,command:20150112-193253:uname-a
BASH[4679]: user=root,ppid=4326,from=10.70.20.20 4763 22,pwd=/root,command:20150112-194716:ps-ef|grep Tail


This article from "vslinux51cto.com" blog, reproduced please contact the author!

A bash configuration file that writes user-executed commands to a syslog under a Linux system

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.