How to keep history from recording sensitive commands
Sometimes for the sake of server security and preventing others from snooping on the command we enter, we can empty the history, and more often, we choose to force the history not to remember the command when entering a special command. Experimental method: first execute the export HISTCONTROL=ignorespace command, and then output the ls-tra, pwd and service mysqld start commands in turn. When we execute the third command, we choose not to remember the command.
[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 (note that this command is preceded by a space)
Then let's take a look at the history.
[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
Did you find out that what we just implemented, service mysqld start is gone?
Note: if you don't want the history to remember which command, just add a space when executing the command.
Of course, one day you want to clear all the history orders can be carried out:
[root@VM_96_242_centos ~] # history-c / / clear all records
[root@VM_96_242_centos ~] # history / / check whether it is emptied
1 2016-12-12 17:12:12 history
[root@VM_96_242_centos ~] #