Change terminal color in Ubuntu for SSH sessions

Well I made the mistake of leaving an SSH session logged in at home and then when I came back to my laptop to shut it down I typed "sudo halt" and then realised I was still on the server and everyone who was accessing the server was kicked off.

Not so much fun and a bit of a ammeter mistake, my solution was to change the colour of my terminal login prompt when in a ssh session. I tend to ssh into my home server quite a lot so I have an alias in my .bashrc file. Your .bashrc file is run when you login.

Here is the one line that you need to add to your ~/.bashrc file using your favourite editor, either gedit, nano or vi will do the trick.

alias home="tput setaf 1; ssh -X -p 675 -i ~/home.key [email protected]; tput setaf 0"

tput changes the prompt text colour, 1 = red and 0 = black. The other stuff is all to do with ssh, the -p is used to specify a custom port and the -i allows me to specify the location of my pgp key.

Unless you logout and back in the alias won't work. Your other option is to simply source the file with the following command.

source .bashrc


Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.