3

I want to change the color of the root prompt after using sudo su. It is currently white. I am using Ubuntu in a VirtualBox VM.

Here is a picture of my terminal:

screenshot of Ubuntu terminal in VirtualBox

Nmath
  • 12,105
  • 8
  • 25
  • 54
Unknown
  • 41
  • 1
  • 4
  • 1
    Does this answer your question? [Is it possible to color the prompt in Bash?](https://askubuntu.com/questions/13892/is-it-possible-to-color-the-prompt-in-bash) – Artur Meinild Oct 02 '21 at 09:18
  • @ArturMeinild there is nothing relevant on changing the color of the terminal in the very old question you marked as a duplicate – vanadium Oct 02 '21 at 10:11
  • You don't think `force_color_prompt=yes` for root is an answer to the OP's question? If not, then it's not possible to understand what the OP is actually asking. – Artur Meinild Oct 02 '21 at 10:14
  • 1
    Does this answer your question? [Changing behavior of bash prompt when functioning as root](https://askubuntu.com/questions/305052/changing-behavior-of-bash-prompt-when-functioning-as-root) – muru Oct 02 '21 at 10:47
  • @ArturMeinild seems clear to me: make it a different color. There is even a picture. – vanadium Oct 02 '21 at 10:54
  • Does this answer your question? [Changing colors for user, host, directory information in terminal command prompt](https://askubuntu.com/questions/123268/changing-colors-for-user-host-directory-information-in-terminal-command-prompt) – vanadium Oct 02 '21 at 16:34

2 Answers2

3

The prompt is defined by the PS1 variable. You can see how it is defined with

~$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

In standard Ubuntu, it is actually being defined with the command:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  • Change 01;32 in the part \[\033[01;32m\] to a different number to change the color of the username@hostname part.
  • Change 01;34 in the part \[\033[01;34m\] to change the color of the folder name.

A list of color codes (adapted from source):

Color       Code
Black       0;30
Red         0;31
Green       0;32
Brown       0;33
Blue        0;34
Magenta     0;35
Cyan        0;36
White       0;37

Replace 0 with 1 to get a light colored version.

This variable is set in your .bashrc configuration file, which is executed each time an interactive shell is opened. Thus, modify the existing command accordingly.

You can change the color of the prompt of the root user in the same way by editing the .bashrc file of the root user, /root/.bashrc. However, to enable a colored prompt for that account, you should also uncomment the line force_color_prompt=yes.

vanadium
  • 82,909
  • 6
  • 116
  • 186
0

This solution is relatively simple, type

nano ~/.bashrc

in the terminal as root. I like to use nano, you may use whatever text editor you wish. Find and uncomment:

#force_color_prompt=yes

in the file, save/write out the file, then pull up a fresh terminal and enter root. You should now have colored root terminal text.

jlwilt
  • 31
  • 5