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