Unifying prompt across Linux node

Unifying prompt across Linux node

For some time I wanted to unify how the Linux prompt is displayed on Order of Code various instances. I wanted it to include the following information:

  • Username.
  • Full hostname.
  • Path to current directory.
  • Displayed as somebody@host.somecompany.com:/usr/bin$ _.
  • Soothing light-green colour for normal user.
  • Red colour for elevated user so that he should be extra careful.
  • Work for all users on the server.

While including all this info might be too much, it might prevent some nasty accidents. Deleting database on wrong server, destroying wrong VM and so on.

Achieving prompt syntax was easy enough with various generators available online. The only tricking part was elevation based coloring having the prompt server wide.

It turns out that there is a nice and neat solution for achieving that. Centos, and other distributions, stores various node-wide scripts in /etc/profile.d directory.

So all I had to do is to put another one that contains instructions on how to format and colour the prompt. I decided to name it colourprompt.sh.

Its logic was super simple: if user ID is different than 0 display prompt in green. If it is (that means elevated to root) then use red.

Related Posts

Leave a reply