How to Stop Ubuntu from Automatically Saving Your Bash Command History

Every time you open the terminal in Ubuntu Linux and type a command, the Bash shell quietly records that command into a hidden text file located in your home directory (~/.bash_history). This allows you to press the “Up” arrow key on your keyboard to instantly recall and rerun previous commands.

However, from a security and privacy standpoint, maintaining a permanent, plain-text log of every command you have ever executed is highly risky. If you accidentally typed a MySQL password, an SSH key, or an API token directly into the command line, that sensitive string is now permanently saved in the history file. Anyone who gains access to your user account can simply read the file and steal your credentials.

You can completely disable the Bash history feature, forcing the terminal to operate with severe amnesia. Once you close the terminal window, all record of your session will instantly vanish.

How to Stop Bash from Saving Command History

You must modify your user’s primary Bash configuration file to unset the history variables.

  1. Open your terminal application (Ctrl+Alt+T).
  2. First, delete your existing, potentially sensitive history file by running:
    rm ~/.bash_history
  3. Next, open your Bash profile configuration in a text editor (like nano):
    nano ~/.bashrc
  4. Scroll all the way down to the very bottom of the file.
  5. Add the following two lines on a new line at the bottom to permanently unset the history file size limits:
    export HISTSIZE=0
    export HISTFILESIZE=0
  6. Press Ctrl+O then Enter to save the file, and Ctrl+X to exit nano.
  7. To apply the changes immediately, run:
    source ~/.bashrc

Bash will immediately stop recording your keystrokes to the hard drive. You can still use the Up arrow to recall commands during your current active session, but the moment you type exit or close the terminal window, the memory is wiped clean forever.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.