Indication of privileges via colors in terminal?

Clash 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 ?
linux centos
add a comment |Â
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 ?
linux centos
2
They shouldn't switch to the root account. They should be usingsudofor 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 groupsudo/wheeldepending on discro.
â ctrl-alt-delor
Jun 22 at 17:05
add a comment |Â
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 ?
linux centos
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 ?
linux centos
asked Jun 22 at 15:08
Gokulnath Kumar
558
558
2
They shouldn't switch to the root account. They should be usingsudofor 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 groupsudo/wheeldepending on discro.
â ctrl-alt-delor
Jun 22 at 17:05
add a comment |Â
2
They shouldn't switch to the root account. They should be usingsudofor 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 groupsudo/wheeldepending 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
add a comment |Â
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=.
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 == 0should be"$(id -u)" == 0.
â Kusalananda
Jun 22 at 16:00
@AndyDalton SettingEUIDfor thebashprocess withEUID=something bashsets it in thebashprocess. 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 forbashfloating around. I'm using 4.4.23 on OpenBSD andEUID=hello bash -c 'echo "$EUID"'printshello.
â Kusalananda
Jun 22 at 16:29
 |Â
show 2 more comments
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=.
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 == 0should be"$(id -u)" == 0.
â Kusalananda
Jun 22 at 16:00
@AndyDalton SettingEUIDfor thebashprocess withEUID=something bashsets it in thebashprocess. 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 forbashfloating around. I'm using 4.4.23 on OpenBSD andEUID=hello bash -c 'echo "$EUID"'printshello.
â Kusalananda
Jun 22 at 16:29
 |Â
show 2 more comments
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=.
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 == 0should be"$(id -u)" == 0.
â Kusalananda
Jun 22 at 16:00
@AndyDalton SettingEUIDfor thebashprocess withEUID=something bashsets it in thebashprocess. 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 forbashfloating around. I'm using 4.4.23 on OpenBSD andEUID=hello bash -c 'echo "$EUID"'printshello.
â Kusalananda
Jun 22 at 16:29
 |Â
show 2 more comments
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=.
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=.
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 == 0should be"$(id -u)" == 0.
â Kusalananda
Jun 22 at 16:00
@AndyDalton SettingEUIDfor thebashprocess withEUID=something bashsets it in thebashprocess. 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 forbashfloating around. I'm using 4.4.23 on OpenBSD andEUID=hello bash -c 'echo "$EUID"'printshello.
â Kusalananda
Jun 22 at 16:29
 |Â
show 2 more comments
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 == 0should be"$(id -u)" == 0.
â Kusalananda
Jun 22 at 16:00
@AndyDalton SettingEUIDfor thebashprocess withEUID=something bashsets it in thebashprocess. 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 forbashfloating around. I'm using 4.4.23 on OpenBSD andEUID=hello bash -c 'echo "$EUID"'printshello.
â 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
 |Â
show 2 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
They shouldn't switch to the root account. They should be using
sudofor 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/wheeldepending on discro.â ctrl-alt-delor
Jun 22 at 17:05