I'd like to make happen in RHEL/CentOS 7.6
anytime you do
su and become root I want the terminal prompt color in that terminal to become red for the duration of that
su session. Type
exit to go back to being whoever you were and I want the prompt color to go back to whatever the previous color was (black).
Same for an SSH window using putty logged in over the network: initially ssh in as user and have a default white shell prompt; do an
su to root and I want the prompt to become red; type exit I want the prompt to go back to white.
so far i did this but it's not working 100%, the color stays red after you type
exit and leave the su session and go back to being user.
if [ $UID -eq 0 ]; then
PS1="\e[31m[\u@\h \W]# "
PS1="[\u@\h \W]# "
Is there a way to make things happen the way I want? I only want it for bash shells.