Before you go, check out these stories!

Hackernoon logoHide the Exported ENV Variables From the History by@epranka

Hide the Exported ENV Variables From the History

Author profile picture

@eprankaEdvinas Pranka

Full-stack developer

Hi, happy to join your community. This is my first post, so I start from the simple one, but useful. Maybe you don't know about it yet.

When you work with the Linux server, sometimes you export some environment variables. Some envs can be neutral like

or something else, but sometimes it must be safe likeย 
ย orย 

The problem is if anyone accesses the server bash and enters theย history command it will see the secrets:

1989  export MYSQL_PASSWORD=my_secret_mysql_password
2000  history

To be safe, before working with the bash, export Linux history control environment variable which is calledย 


$ export HISTCONTROL=ignorespace

ignorespaceย means that if you leave the space before any bash command, it will be ignored in history.

So while exporting the secret environment variable, enter the space beforeย export

$ export HISTCONTROL=ignorespace
# keep in mind space before export
$  export MYSQL_PASSWORD=my_secret_mysql_password
$ history

So now, the Mysql password will be ignored in history

1999  export HISTCONTROL=ignorespace
2000  history

This method is not only for environment variables, but it can also hide any bash command, evenย 

export HISTCONTROL=ignorespace
ย itself.

Follow onย Twitter,ย GitHub, and letโ€™s connect onย LinkedIn

Good luck and be safe! :)

Previously published at


Join Hacker Noon

Create your free account to unlock your custom reading experience.