您的位置:首页 > 其它

如何让历史记录不记录敏感命令

2016-12-12 17:46 260 查看
有时候为了服务器安全,防止别人窥探我们输入的命令,我们可以清空历史记录,而更多的时候,我们选择的是在输入特殊命令时候,强制历史记录不记住该命令。实验方法:先执行export HISTCONTROL=ignorespace 命令,然后依次输出ls -tra ,pwd和service mysqld start 的命令,当执行第三个命令的时候,我们选择不记住该命令。

[root@VM_96_242_centos ~]# export HISTCONTROL=ignorespace
[root@VM_96_242_centos ~]# ls -ltr
total 168
-rw-r--r-- 1 root root 5520 Dec 25 2014 install.log.syslog
-rw-r--r-- 1 root root 12754 Dec 25 2014 install.log
-rw------- 1 root root 2005 Dec 25 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 12 Dec 9 21:11 a.txt

[root@VM_96_242_centos ~]# pwd

[root@VM_96_242_centos ~]# service mysqld start (注意这条命令的最前面是一个空格)
然后我们来查看历史记录
[root@VM_96_242_centos ~]# history |tail -3
844 2016-12-12 17:01:55 ls -ltr
845 2016-12-12 17:01:59 pwd
846 2016-12-12 17:02:36 history |tail -3

是不是发现我们刚刚执行的,service mysqld start 没有了
注意:如果不想让历史记录记住哪条命令,直接在执行命令的时候,添加空格就可以。

当然哪天你想清空所有历史命令可以执行:
[root@VM_96_242_centos ~]# history -c //清空所有记录
[root@VM_96_242_centos ~]# history //查看是否被清空
1 2016-12-12 17:12:12 history
[root@VM_96_242_centos ~]#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  安全 服务器 service