When you type commands into the terminal in Ubuntu Linux, the Bash shell automatically records every single command you execute and saves it to a hidden file in your home directory called .bash_history. This feature is incredibly useful for recalling a long, complex string you typed yesterday (by pressing the Up arrow key) or searching your past commands using Ctrl+R.
However, from a security and privacy standpoint, this history file is a massive vulnerability. If you frequently pass passwords in plain text (e.g., in a MySQL connection string), use sensitive API keys in curl requests, or share a server with other users, anyone with read access to your home directory can see exactly what you have been doing.
If you require strict operational security, you can configure Bash to completely stop recording your history.
How to Disable Bash History for the Current Session
If you only want to stop recording temporarily (perhaps you are about to run a few sensitive commands but want history to resume normally afterward), you can use the following command:
set +o history
Everything you type in the terminal after hitting Enter will be instantly forgotten. To turn history back on before you close the terminal, run:
set -o history
How to Disable Bash History Permanently
If you never want Ubuntu to save another command to the disk, you need to modify your user’s Bash profile.
- Open your terminal application (
Ctrl+Alt+T). - First, wipe your existing history clean so no old data remains:
history -c && rm ~/.bash_history
- Next, open your
.bashrcfile using a text editor like nano:
nano ~/.bashrc
- Scroll to the very bottom of the file and paste the following line:
export HISTSIZE=0
- Save the file (
Ctrl+O,Enter) and exit nano (Ctrl+X). - Apply the changes immediately by sourcing the file:
source ~/.bashrc
By setting the maximum history size to zero, you have effectively neutered the tracking feature. Bash will no longer write anything to the disk, ensuring your command-line activities remain completely private.