Avoiding Adding Commands to Bash History

It's generally a bad idea to enter passwords on the command line, because other processes can see these passwords in various places and also because, by default, your command history is saved into a ~/.bash_history file in your home directory after you exit your shell session.

$ sudo rabbitmqctl authenticate_user openstack SomeS3cretPassword
Authenticating user "openstack" ...
Success

Unfortunately, SomeS3cretPassword will be recorded in ~/.bash_history.

$ history | grep rabbitmqctl
   67  sudo rabbitmqctl authenticate_user openstack SomeS3cretPassword
   68  history | grep rabbitmqctl

There is a way to avoid this -- simply add one or more blank spaces to the beginning of the command:

$  sudo rabbitmqctl authenticate_user openstack SomeS3cretPassword
Authenticating user "openstack" ...
Success
$ history | grep rabbitmqctl
   68  history | grep rabbitmqctl

Notice the extra space between $ and sudo in the first line above.

Posted in on
Tagged with bash commandline

Comments