The output of the command is usually not stored anywhere and closing the window is enough. But the command itself is stored: in the shell's history.
To remove it from there it is best to first close all terminal windows. Normally, the history is written to the file ~/.bash_history
when the shell ends and directly manipulating the file won't help because it gets overwritten upon shell's exit. There are ways to configure history
differently but the easiest is to simply close all terminal windows.
Now open one new terminal window and type
history
or
history | grep echo
Sample output:
...
2007 echo -n "<some text generated by hand from the site's domains>" | sha256sum |cut -c-20
2008 echo -n "secret" | sha256sum |cut -c-20
2009 echo -n "secret"
2010 history
Here you see that not only the "malicious" command is stored but also the "correct" one. You can delete it with
history -d 2009
where 2009
is the number in the first column. Change that appropriately. Now:
history
...
2007 echo -n "<some text generated by hand from the site's domains>" | sha256sum |cut -c-20
2008 echo -n "secret" | sha256sum |cut -c-20
2009 history
2010 history -d 2009
2011 history
For the future you might want to prefix your echo … | sha256sum …
with a space, i.e.
_echo -n "secret" | sha256sum |cut -c-20 # The '_' indicates a leading space
This way the complete command won't be recorded in the history. The behaviour is controlled by the HISTCONTROL variable (man bash
):
HISTCONTROL
A colon-separated list of values controlling how commands are saved on
the history list. If the list of values includes ignorespace
, lines
which begin with a space character are not saved in the history list. A
value of ignoredups
causes lines matching the previous history entry
to not be saved. A value of ignoreboth
is shorthand for ignorespace
and ignoredups
.
You may want to add export HISTCONTROL='ignoreboth'
to your ~/.bashrc
to achieve that.
stty -echo; tr -d '\n' | sha256sum | cut -c-20; stty echo
instead and then paste the password to stdin, press enter and ctrl-d. This way you get the same result, but nothing recorded in your history or scrollback buffer. – Sebastian Stark Aug 31 '18 at 09:51