There is no technical reason to change the color of the terminal console, but anyone can issue commands as another user or logged in to the wrong machine because all of the prompts look the same.

That is what we are going to define:

Find out what is your current prompt style code:

echo $PS1

To change your prompt style issue the following command replacing the bold text with the desired style:

export PS1="put_the_new_style_here"

Try the following two styles to see how it works:

export PS1="\[$(tput setaf 3)\]\t \u@\h:\w $ \[$(tput sgr0)\]"
export PS1="\[$(tput setaf 1)\]\t \u@\h:\W $ \[$(tput sgr0)\]"

Note the difference between the lines. Just one number changed: 3 to 1. It is because 3 means Yellow and 1 means Red.

Various color codes for the tput command

  • 0 = Black
  • 1 = Red
  • 2 = Green
  • 3 = Yellow
  • 4 = Blue
  • 5 = Magenta
  • 6 = Cyan
  • 7 = White

As soon as you exit the terminal this configuration will disappear. To make it permanent edit the file ~/.bashrc (for Ubuntu 20.04, for others can be: .bash_profile):

sudo nano ~/.bashrc

And append the defined color definition line at the end.

There are other ways to create more complex color schemes, such as changing the color of specific pieces of the prompt or applying Bold or Italic:

export PS1='\[\033[01;33m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

The syntax follows this structure \[\033[X;Y]m\].

Where the X is the attribute and Y is the color.

Color Value
Green 32
Red 31
Black 30
Blue 34
Cyan 36
Purple 35
Yellow 33
White 37

Most common attributes:

Attribute Value Purpose
0 Normal text (This is the default value even if no attribute is set)
1 In the Ubuntu Terminal, this value specifies bold text
2 Dim text
4 Text underlining
5 For blinking text
7 Reverses text and background colours
8 For hidden text

BUG FIXING

There is a very common issue with the history that can be navigated with the arrow keys up and down that cna be caused by the prompt customisation.

A work around for this issue is to use the ‘[]‘ around non-printing characters in your PS1 variable, like this:

export PS1="\[\e[m\]\u@\e[1;31m\h\e[m \W ⇨ \[\e[m\] "
export PS1="\[\e[m\]\u@\[\e[1;31m\]\h\[\e[m\] \W ⇨ \[\e[m\] "

Have fun!


BONUS

For privacy consider this prompt when sharing or recording your screen.

export PS1="\[$(tput setaf 4)\]$ \[$(tput sgr0)\]"

On Kali

export PS1="%F{%(#.blue.green)}┌──${debian_chroot:+()─}${VIRTUAL_ENV:+($(basename $VIRTUAL_ENV))─}[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.blue.green)}] 
└─%B%(#.%F{red}#.%F{blue}$)%b%F{reset} "