Is it possible to open an incognito session in bash
?
For example, when we need to enter passwords in commands and don't want bash
to add them to history.
Is it possible to open an incognito session in bash
?
For example, when we need to enter passwords in commands and don't want bash
to add them to history.
When you want bash
to stop logging your commands, just unset the HISTFILE
variable:
HISTFILE=
All further commands should then no longer be logged to .bash_history
.
On the other hand, if you are actually supplying passwords as arguments to commands, you're already doing something wrong. .bash_history
is not world-readable and therefore not the biggest threat in this situation:
ps
and /proc
are the big problem. All users on the system can see the commands you're currently running with all of their arguments. Passing passwords as command line arguments is therefore inherently insecure. Use environment variables or config files (that you have chmodded 600) to securely supply passwords.
unset HISTFILE
has a similar effect. I have a function for this: n() { HISTFILE=; PS1="~${PS1#\~}"; }
. That way I can clearly see whether I am in "incognito mode" or not.
– Lekensteyn
Oct 03 '14 at 17:05
HISTCONTROL=ignorespace
If this option is not already set for bash
, it may be just what you need. It is less debilitating than disabling all history. With that set, any commandline starting with a space character will not be saved to the history list.
From these related links:
You can temporarily disable history: set +o history
set +o history
...
set -o history
There is a difference between disabling history and unsetting HISTFILE
:
HISTFILE=
date
ls
HISTFILE=~/.bash_history
history
outputs something like this:
84 HISTFILE=
85 date
87 ls
88 HISTFILE=~/.bash_history
89 history
i.e. all commands are saved in the history list. Type exit
to save it.
But
set +o history
date
ls
set -o history
history
outputs something like this:
115 set +o history
116 history
Summary:
set +o history
for long sessions.
HISTCONTROL
and <space>command
at other time.
cat | bash
will run a non-interactivebash
without prompt, command-line editing (just the line discipline's internal editor) or history. – Stéphane Chazelas Oct 02 '14 at 20:47secrectcommand
will not be in bash history. – Martin Thoma Oct 09 '14 at 20:34