Bash历史记录可以通过删除包含的文件来删除。如何保护历史记录不被清除/删除?
sudo chattr +a ~$USER/.bash_history
sudo chattr +i ~$USER/.profile
/etc/bash.bashrc
或/etc/.profile
中:# #Prevent unset of histfile, /etc/profile
HISTFILE=~/.bash_history
HISTSIZE=10000
HISTFILESIZE=999999
# Don't let the users enter commands that are ignored# in the history file
HISTIGNORE=""
HISTCONTROL=""
readonly HISTFILE
readonly HISTSIZE
readonly HISTFILESIZE
readonly HISTIGNORE
readonly HISTCONTROL
export HISTFILE HISTSIZE HISTFILESIZE HISTIGNORE HISTCONTROL
CAP_LINUX_IMMUTABLE
权限的进程都可以删除不可变位。kill -9 $$
这个命令。该命令将阻止写入历史记录。所以你所问的是毫无意义的。如果你不信任用户,请不要让他们进入你的系统。
如果这个问题是为了追踪黑客的行为...你可以完全忘记这一点;当他们使用你的系统时,他们不太可能使用bash,而且这个历史记录只适用于bash。
一个更优越的选择是使用grsecurity或安装acct(GNU会计工具)。
+i
= 不可变,防止所有更改; +a
= 仅追加。两者均适用于特定的文件系统。 - ilkkachu+i
。 - heemayl.bash_history
文件免于被删除。如果将其权限位设置为只读,bash将无法写入其中。~/.bashrc
中为rm
创建一个别名,这样每次你想要删除东西时,它都会询问你是否确定(y/n)
。~/.bashrc
文件中。alias rm="rm -i"
chmod 600 ~/.bashrc
/etc/skel/.bashrc
或每个用户的~/.bashrc
。readonly HISTFILE
readonly HISTFILESIZE
readonly HISTSIZE
readonly HISTCMD
readonly HISTCONTROL
readonly HISTIGNORE