在/etc/profile配置文件的末尾加入以下脚本代码,或者单独生成一个文件,置于/etc/profile.d/目录下,实现SSH远程登陆用户IP地址和终端操作的日志记录。
historyUSER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`if [ "$USER_IP" = "" ]then USER_IP=`hostname`fiif [ ! -d /tmp/history ]then mkdir /tmp/history chmod 777 /tmp/historyfiif [ ! -d /tmp/history/${LOGNAME} ]then mkdir /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