跳至正文

history命令记录ip

  • 修改配置文件
# vim /etc/profile
USER_IP=`who -u am i 2>/dev/null | awk '{print $NF}' | sed -e 's/[()]//g'`
if ["$USER_IP" = ""];then
USER_IP=`hostname`
fi
export HISTTIMEFORMAT="%F %T $USER_IP `whoami`"
short -s histappend
export PROMPT_COMMAND="history -a"
  • 添加 a 权限,让管理员也无法删除history文件,清除历史记录都不行
chattr +a /root/.bash_history
lsattr /root/.bash_history
  • 重定向history文件
cat .bash_history >> his.txt