Ubuntu – history doesn’t display as sudo user

command linesudo

On a few of my ubuntu installations, when I run sudo su and become sudo user, I can type history and view a list of commands run as sudo user. However, on my one ubuntu installation, for some reason when I run sudo su and type history, I just get this:

$ sudo su
# history
1  history 

But I know for certain that a lot of commands were run as sudo user, but when I ssh out and ssh back into my ubuntu server, they do not display, like how they do on the other servers. Do I have some switch or something disabled on this one server? How can I regain access to view the history of commands run as sudo user?

Best Answer

Some possibilities why you do not keep shell history:

  • Your root shell is not /bin/bash but /bin/sh (symlinked to /bin/dash). Change this with the chsh command.
  • The filesystem where /root resides is mounted read-only, so the history file cannot be written.
  • The variable HISTFILE is set to a value other than /root/.bash_history. An empty file disables history, other values are used as location to write the history to.
Related Question