3

I have Ubuntu 18.04 on my win10, and I usually create my password with this line of code:

echo -n "<some text generated by hand from the site's domains>" | sha256sum |cut -c-20 

But today I accidentally pressed Enter after the echo command.

Does Ubuntu save its terminal outputs in a file? Am I safe just using the clear command?

Do you guys recommend a better solution so my password is different from each other and hard to compute a new one based on some of my other passwords?

Thanks.

  • 1
    Your terminal likely forgets the output on close, but your shell keeps a record of the command history on disk. – dsstorefile1 Aug 31 '18 at 9:03
  • 1
    It's not exactly an answer, so posting this as a comment: You could use 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 9:51
  • 3
    Possible duplicate of Terminal 'incognito mode'? – Helio Aug 31 '18 at 13:35
3

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.

  • 1
    While the terminal is still open, you can also remove the line directly from the history in memory, which hasn't been saved to disk yet. Use history -c to clear the complete history of the respective shell session, or history to show the list and history -d NUMBER to delete only the entry with the specific NUMBER in the list. – Byte Commander Aug 31 '18 at 9:40
  • @ByteCommander Yes, the history command has quite a lot of useful options. I just thought closing all windows might be the easiest. We could also setup HISTIGNORE so that echo … sha256sum … | cut lines aren't recorded at all (no matter the leading space). – PerlDuck Aug 31 '18 at 9:49
  • thanks man(for the output part) (i already knew about space button and i remember typing it to my question but it's not there :) ,but still a thanks) – Sayyed Alireza Rezaei Asl Sep 1 '18 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.