Operating System - HP-UX
1837672 Members
3841 Online
110117 Solutions
New Discussion

History feature for root shell

 
SOLVED
Go to solution
Timothy DiBenedetto_1
Occasional Advisor

History feature for root shell

How can I enable the history feature for use when I login as root? I am using 11.i
Thank you.
5 REPLIES 5
Steven E. Protter
Exalted Contributor
Solution

Re: History feature for root shell

HISTFILE=/root/.sh_history
export HISTFILE
HISTSIZE=5000
export HISTSIZE

You can put it in /etc/profile for all users or roots .profile file.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Pete Randall
Outstanding Contributor

Re: History feature for root shell

All you need is the HISTFILE variable in (a) profile:

HISTFILE=/tmp/.sh_history.$(whoami)
export HISTFILE

And don't forget to "set -o vi" in root's startup as well.


Pete


Pete
Robert Gamble
Respected Contributor

Re: History feature for root shell

I recommend you do not place your HISTFILE into /tmp as Pete suggests. Even if they can't read it, it could be breached. Put it in a directory only root has access to, such as /root that Steven suggested.

I have used the method Steven suggested many times, and it works very well.

Timothy DiBenedetto_1
Occasional Advisor

Re: History feature for root shell

Perfect. I was trying to use the wrong histfile name. Thanks.
John Dvorchak
Honored Contributor

Re: History feature for root shell

One thing that I like to do is give everyone, that has root access, their own history file. That way if you ever want to know who typed what you can find out. Also I like to have my own history file on those systems that have multiple Admins.

In /root/.profile I do the following:

# sets .sh_hist file to id of user

if [ "`tty`" = "/dev/console" ]
then
REAL=console
else
REAL=`logname`
fi

HISTFILE=$HOME/.sh_$REAL
export HISTSIZE=10000; export HISTSIZE
If it has wheels or a skirt, you can't afford it.