ncsa / xcat-tools

Useful tools for xCAT
BSD 3-Clause "New" or "Revised" License
8 stars 0 forks source link

Distinct root history per-sudo-user on cluster admin node #17

Closed andylytical closed 2 years ago

andylytical commented 4 years ago

Multiple admins on a system are often on root at the same time on the management node. When this happens, the root user's shell history winds up being updated by each separate user commands. This causes consternation when the admins try to find previous commands and could cause serious issues if the wrong command gets executed.

I've found a method for each sudo root user to have a history file which is theirs and theirs alone.

This should also allow for better tracking of who did what at what time on the system.

The change is fairly simple and involves the following code being added to ~root/.bash_profile and each history file is created in ~root/.history/.

The code that does this is:

if [ -n "$SUDO_USER" ]; then

make the shell history user-dependent so that

# we're not all putting our commands into everyone
# else's history.

if [ ! -d $HOME/.history ]
then
    mkdir --mode=700 $HOME/.history
fi
EXTENDED_HISTORY=ON
readonly EXTENDED_HISTORY
export EXTENDED_HISTORY
HISTFILE=$HOME/.history/${SUDO_USER}
readonly HISTFILE
export HISTFILE

fi

The EXTENDED_HISTORY variable adds date and time to each history line making tracking easier.