Coloured & Named Terminal Prompt On CentOS

back to tech articles
CentOS 6, Bash

If you are like me, you might have 3 SSH sessions open in your terminal window at the same time. Flicking between them and hitting up twice and then return could be disastrous on the wrong window! I’ve been there before 🙁

So, here’s a little trick to colour the output of the server at the prompt when you SSH in 🙂 This is a per-user tweak; super sweet.

1
2
$ ssh jason@8.8.8.8
$ vi .bashrc

Add the following line to the bottom of the file and tweak the part where it says servername.

1
2
# custom bash
export PS1="\e[0;32m\u\e[m\e[0;37m@\e[m\e[1;32mservername\e[m [\e[1;37m\W\e[m] \$ "

Save and exit, logout and login again. Cool, yes?

Some more colours are available to you than what I have used.

Leave a Reply

Your email address will not be published. Required fields are marked *