Indication of privileges via colors in terminal?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I wanted to configure terminal settings in CentOS7 in such a way, that whenever users works or switches to root user account. The terminal text should be displayed in RED color (which is an indication to the user to be more careful for an user on what he is executing). And for all other normal user accounts, the terminal text should be in green color. Is this achievable ?







share|improve this question















  • 2




    They shouldn't switch to the root account. They should be using sudo for every single command they need to run as root. That way you would be able to keep track of who did what, and when. This is obviously my personal opinion though. The root account should already be set up with a significantly different prompt, exactly for this reason. Traditionally, a # prompt is used for root.
    – Kusalananda
    Jun 22 at 15:11











  • Yep you are absolutely right. I just thought of adding one more indication as the color has little more precedence than the text. And obviously our goal is to enable only sudo rights but at this point of time, its not done but soon we need to work on it. Now only administrators have the direct root access (which is not a good idea though).
    – Gokulnath Kumar
    Jun 22 at 15:18










  • Setting up a simple sudo configuration should take a few minutes. Most distros will give full sudo privileges to anyone in group sudo/wheel depending on discro.
    – ctrl-alt-delor
    Jun 22 at 17:05














up vote
0
down vote

favorite












I wanted to configure terminal settings in CentOS7 in such a way, that whenever users works or switches to root user account. The terminal text should be displayed in RED color (which is an indication to the user to be more careful for an user on what he is executing). And for all other normal user accounts, the terminal text should be in green color. Is this achievable ?







share|improve this question















  • 2




    They shouldn't switch to the root account. They should be using sudo for every single command they need to run as root. That way you would be able to keep track of who did what, and when. This is obviously my personal opinion though. The root account should already be set up with a significantly different prompt, exactly for this reason. Traditionally, a # prompt is used for root.
    – Kusalananda
    Jun 22 at 15:11











  • Yep you are absolutely right. I just thought of adding one more indication as the color has little more precedence than the text. And obviously our goal is to enable only sudo rights but at this point of time, its not done but soon we need to work on it. Now only administrators have the direct root access (which is not a good idea though).
    – Gokulnath Kumar
    Jun 22 at 15:18










  • Setting up a simple sudo configuration should take a few minutes. Most distros will give full sudo privileges to anyone in group sudo/wheel depending on discro.
    – ctrl-alt-delor
    Jun 22 at 17:05












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I wanted to configure terminal settings in CentOS7 in such a way, that whenever users works or switches to root user account. The terminal text should be displayed in RED color (which is an indication to the user to be more careful for an user on what he is executing). And for all other normal user accounts, the terminal text should be in green color. Is this achievable ?







share|improve this question











I wanted to configure terminal settings in CentOS7 in such a way, that whenever users works or switches to root user account. The terminal text should be displayed in RED color (which is an indication to the user to be more careful for an user on what he is executing). And for all other normal user accounts, the terminal text should be in green color. Is this achievable ?









share|improve this question










share|improve this question




share|improve this question









asked Jun 22 at 15:08









Gokulnath Kumar

558




558







  • 2




    They shouldn't switch to the root account. They should be using sudo for every single command they need to run as root. That way you would be able to keep track of who did what, and when. This is obviously my personal opinion though. The root account should already be set up with a significantly different prompt, exactly for this reason. Traditionally, a # prompt is used for root.
    – Kusalananda
    Jun 22 at 15:11











  • Yep you are absolutely right. I just thought of adding one more indication as the color has little more precedence than the text. And obviously our goal is to enable only sudo rights but at this point of time, its not done but soon we need to work on it. Now only administrators have the direct root access (which is not a good idea though).
    – Gokulnath Kumar
    Jun 22 at 15:18










  • Setting up a simple sudo configuration should take a few minutes. Most distros will give full sudo privileges to anyone in group sudo/wheel depending on discro.
    – ctrl-alt-delor
    Jun 22 at 17:05












  • 2




    They shouldn't switch to the root account. They should be using sudo for every single command they need to run as root. That way you would be able to keep track of who did what, and when. This is obviously my personal opinion though. The root account should already be set up with a significantly different prompt, exactly for this reason. Traditionally, a # prompt is used for root.
    – Kusalananda
    Jun 22 at 15:11











  • Yep you are absolutely right. I just thought of adding one more indication as the color has little more precedence than the text. And obviously our goal is to enable only sudo rights but at this point of time, its not done but soon we need to work on it. Now only administrators have the direct root access (which is not a good idea though).
    – Gokulnath Kumar
    Jun 22 at 15:18










  • Setting up a simple sudo configuration should take a few minutes. Most distros will give full sudo privileges to anyone in group sudo/wheel depending on discro.
    – ctrl-alt-delor
    Jun 22 at 17:05







2




2




They shouldn't switch to the root account. They should be using sudo for every single command they need to run as root. That way you would be able to keep track of who did what, and when. This is obviously my personal opinion though. The root account should already be set up with a significantly different prompt, exactly for this reason. Traditionally, a # prompt is used for root.
– Kusalananda
Jun 22 at 15:11





They shouldn't switch to the root account. They should be using sudo for every single command they need to run as root. That way you would be able to keep track of who did what, and when. This is obviously my personal opinion though. The root account should already be set up with a significantly different prompt, exactly for this reason. Traditionally, a # prompt is used for root.
– Kusalananda
Jun 22 at 15:11













Yep you are absolutely right. I just thought of adding one more indication as the color has little more precedence than the text. And obviously our goal is to enable only sudo rights but at this point of time, its not done but soon we need to work on it. Now only administrators have the direct root access (which is not a good idea though).
– Gokulnath Kumar
Jun 22 at 15:18




Yep you are absolutely right. I just thought of adding one more indication as the color has little more precedence than the text. And obviously our goal is to enable only sudo rights but at this point of time, its not done but soon we need to work on it. Now only administrators have the direct root access (which is not a good idea though).
– Gokulnath Kumar
Jun 22 at 15:18












Setting up a simple sudo configuration should take a few minutes. Most distros will give full sudo privileges to anyone in group sudo/wheel depending on discro.
– ctrl-alt-delor
Jun 22 at 17:05




Setting up a simple sudo configuration should take a few minutes. Most distros will give full sudo privileges to anyone in group sudo/wheel depending on discro.
– ctrl-alt-delor
Jun 22 at 17:05










1 Answer
1






active

oldest

votes

















up vote
2
down vote













I agree with the comments above with respect to using sudo over logging in as root. That said, here's a variation of something from /etc/bash/bashrc on my Gentoo box that I think does what you want:



if [[ "$(id -u)" == "0" ]] ; then
PS1+='[33[01;31m]h[33[01;36m] w $[33[00m] '
else
PS1+='[33[01;32m]u@h[33[01;36m] w $[33[00m] '
fi


Depending on where you put it, might want to change PS1+= to PS1=.






share|improve this answer























  • What is the right place to put this in? How about /etc/profile.d/somename.sh ?
    – Gokulnath Kumar
    Jun 22 at 15:41










  • I think that'd be a reasonable place to try. It's a question of "where else does it get set, and when".
    – Andy Dalton
    Jun 22 at 15:48






  • 1




    $EUID == 0 should be "$(id -u)" == 0.
    – Kusalananda
    Jun 22 at 16:00










  • @AndyDalton Setting EUID for the bash process with EUID=something bash sets it in the bash process. Using as done here seems to be safe, but since it's a user-supplied value, using it wrongly, as in [ $EUID -eq 0 ] could lead to oddness, and potentially to a security hole. It is therefore safer to use "$( id -u )".
    – Kusalananda
    Jun 22 at 16:18










  • @AndyDalton There might be different patches for bash floating around. I'm using 4.4.23 on OpenBSD and EUID=hello bash -c 'echo "$EUID"' prints hello.
    – Kusalananda
    Jun 22 at 16:29










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451329%2findication-of-privileges-via-colors-in-terminal%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













I agree with the comments above with respect to using sudo over logging in as root. That said, here's a variation of something from /etc/bash/bashrc on my Gentoo box that I think does what you want:



if [[ "$(id -u)" == "0" ]] ; then
PS1+='[33[01;31m]h[33[01;36m] w $[33[00m] '
else
PS1+='[33[01;32m]u@h[33[01;36m] w $[33[00m] '
fi


Depending on where you put it, might want to change PS1+= to PS1=.






share|improve this answer























  • What is the right place to put this in? How about /etc/profile.d/somename.sh ?
    – Gokulnath Kumar
    Jun 22 at 15:41










  • I think that'd be a reasonable place to try. It's a question of "where else does it get set, and when".
    – Andy Dalton
    Jun 22 at 15:48






  • 1




    $EUID == 0 should be "$(id -u)" == 0.
    – Kusalananda
    Jun 22 at 16:00










  • @AndyDalton Setting EUID for the bash process with EUID=something bash sets it in the bash process. Using as done here seems to be safe, but since it's a user-supplied value, using it wrongly, as in [ $EUID -eq 0 ] could lead to oddness, and potentially to a security hole. It is therefore safer to use "$( id -u )".
    – Kusalananda
    Jun 22 at 16:18










  • @AndyDalton There might be different patches for bash floating around. I'm using 4.4.23 on OpenBSD and EUID=hello bash -c 'echo "$EUID"' prints hello.
    – Kusalananda
    Jun 22 at 16:29














up vote
2
down vote













I agree with the comments above with respect to using sudo over logging in as root. That said, here's a variation of something from /etc/bash/bashrc on my Gentoo box that I think does what you want:



if [[ "$(id -u)" == "0" ]] ; then
PS1+='[33[01;31m]h[33[01;36m] w $[33[00m] '
else
PS1+='[33[01;32m]u@h[33[01;36m] w $[33[00m] '
fi


Depending on where you put it, might want to change PS1+= to PS1=.






share|improve this answer























  • What is the right place to put this in? How about /etc/profile.d/somename.sh ?
    – Gokulnath Kumar
    Jun 22 at 15:41










  • I think that'd be a reasonable place to try. It's a question of "where else does it get set, and when".
    – Andy Dalton
    Jun 22 at 15:48






  • 1




    $EUID == 0 should be "$(id -u)" == 0.
    – Kusalananda
    Jun 22 at 16:00










  • @AndyDalton Setting EUID for the bash process with EUID=something bash sets it in the bash process. Using as done here seems to be safe, but since it's a user-supplied value, using it wrongly, as in [ $EUID -eq 0 ] could lead to oddness, and potentially to a security hole. It is therefore safer to use "$( id -u )".
    – Kusalananda
    Jun 22 at 16:18










  • @AndyDalton There might be different patches for bash floating around. I'm using 4.4.23 on OpenBSD and EUID=hello bash -c 'echo "$EUID"' prints hello.
    – Kusalananda
    Jun 22 at 16:29












up vote
2
down vote










up vote
2
down vote









I agree with the comments above with respect to using sudo over logging in as root. That said, here's a variation of something from /etc/bash/bashrc on my Gentoo box that I think does what you want:



if [[ "$(id -u)" == "0" ]] ; then
PS1+='[33[01;31m]h[33[01;36m] w $[33[00m] '
else
PS1+='[33[01;32m]u@h[33[01;36m] w $[33[00m] '
fi


Depending on where you put it, might want to change PS1+= to PS1=.






share|improve this answer















I agree with the comments above with respect to using sudo over logging in as root. That said, here's a variation of something from /etc/bash/bashrc on my Gentoo box that I think does what you want:



if [[ "$(id -u)" == "0" ]] ; then
PS1+='[33[01;31m]h[33[01;36m] w $[33[00m] '
else
PS1+='[33[01;32m]u@h[33[01;36m] w $[33[00m] '
fi


Depending on where you put it, might want to change PS1+= to PS1=.







share|improve this answer















share|improve this answer



share|improve this answer








edited Jun 22 at 16:30









Kusalananda

101k13199312




101k13199312











answered Jun 22 at 15:31









Andy Dalton

4,7111520




4,7111520











  • What is the right place to put this in? How about /etc/profile.d/somename.sh ?
    – Gokulnath Kumar
    Jun 22 at 15:41










  • I think that'd be a reasonable place to try. It's a question of "where else does it get set, and when".
    – Andy Dalton
    Jun 22 at 15:48






  • 1




    $EUID == 0 should be "$(id -u)" == 0.
    – Kusalananda
    Jun 22 at 16:00










  • @AndyDalton Setting EUID for the bash process with EUID=something bash sets it in the bash process. Using as done here seems to be safe, but since it's a user-supplied value, using it wrongly, as in [ $EUID -eq 0 ] could lead to oddness, and potentially to a security hole. It is therefore safer to use "$( id -u )".
    – Kusalananda
    Jun 22 at 16:18










  • @AndyDalton There might be different patches for bash floating around. I'm using 4.4.23 on OpenBSD and EUID=hello bash -c 'echo "$EUID"' prints hello.
    – Kusalananda
    Jun 22 at 16:29
















  • What is the right place to put this in? How about /etc/profile.d/somename.sh ?
    – Gokulnath Kumar
    Jun 22 at 15:41










  • I think that'd be a reasonable place to try. It's a question of "where else does it get set, and when".
    – Andy Dalton
    Jun 22 at 15:48






  • 1




    $EUID == 0 should be "$(id -u)" == 0.
    – Kusalananda
    Jun 22 at 16:00










  • @AndyDalton Setting EUID for the bash process with EUID=something bash sets it in the bash process. Using as done here seems to be safe, but since it's a user-supplied value, using it wrongly, as in [ $EUID -eq 0 ] could lead to oddness, and potentially to a security hole. It is therefore safer to use "$( id -u )".
    – Kusalananda
    Jun 22 at 16:18










  • @AndyDalton There might be different patches for bash floating around. I'm using 4.4.23 on OpenBSD and EUID=hello bash -c 'echo "$EUID"' prints hello.
    – Kusalananda
    Jun 22 at 16:29















What is the right place to put this in? How about /etc/profile.d/somename.sh ?
– Gokulnath Kumar
Jun 22 at 15:41




What is the right place to put this in? How about /etc/profile.d/somename.sh ?
– Gokulnath Kumar
Jun 22 at 15:41












I think that'd be a reasonable place to try. It's a question of "where else does it get set, and when".
– Andy Dalton
Jun 22 at 15:48




I think that'd be a reasonable place to try. It's a question of "where else does it get set, and when".
– Andy Dalton
Jun 22 at 15:48




1




1




$EUID == 0 should be "$(id -u)" == 0.
– Kusalananda
Jun 22 at 16:00




$EUID == 0 should be "$(id -u)" == 0.
– Kusalananda
Jun 22 at 16:00












@AndyDalton Setting EUID for the bash process with EUID=something bash sets it in the bash process. Using as done here seems to be safe, but since it's a user-supplied value, using it wrongly, as in [ $EUID -eq 0 ] could lead to oddness, and potentially to a security hole. It is therefore safer to use "$( id -u )".
– Kusalananda
Jun 22 at 16:18




@AndyDalton Setting EUID for the bash process with EUID=something bash sets it in the bash process. Using as done here seems to be safe, but since it's a user-supplied value, using it wrongly, as in [ $EUID -eq 0 ] could lead to oddness, and potentially to a security hole. It is therefore safer to use "$( id -u )".
– Kusalananda
Jun 22 at 16:18












@AndyDalton There might be different patches for bash floating around. I'm using 4.4.23 on OpenBSD and EUID=hello bash -c 'echo "$EUID"' prints hello.
– Kusalananda
Jun 22 at 16:29




@AndyDalton There might be different patches for bash floating around. I'm using 4.4.23 on OpenBSD and EUID=hello bash -c 'echo "$EUID"' prints hello.
– Kusalananda
Jun 22 at 16:29












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451329%2findication-of-privileges-via-colors-in-terminal%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)