I would like to have my terminal colors changed whenever I am connected (through ssh) to another linux machine.

This way, I know that I am putting commands in a remote computer just by looking at the terminal.

I would like the original color configuration to be back whenever I leave the ssh connection.

Does anybody know if this is possible and how to implement it?

  • You might want to mention what terminal program you're using. – Daniel Beck Jan 18 '12 at 18:34
  • I am using Ubuntu gnome-terminal – Edu Jan 20 '12 at 12:57

One way to solve this is to configure prompt on your computer(s) so that it looks different, in a way specific to that machine. For example, you can assign a color to each machine and use that color for the host part of the prompt. (How to do that is another question.)

When you start an ssh session, your local terminal will be receiving the color codes along with prompt, so (as long as your prompt is configured correctly) you do not have to do anything special to revert it back.

Then using any terminal emulator that supports colors should result in correct coloring.

I use this approach quite frequently with PuTTY and several remote machines (all Debian). Even sshing from one session to other (i.e., connecting via PuTTY to machine A and issuing ssh B) works perfectly.

However, the pitfall is that not all terminals will support colors correctly, but from your question I can't see how big deal is it for you.

  • This is correct, the remote systems are where the terminal colors are defined, was just going to answer, but you beat me to it. So, he just needs to make each system (including local) unique. – skub Jan 18 '12 at 19:04
  • How would one perform this though? – Sion Jan 18 '12 at 19:14
  • @Sion By setting PS1 in .bashrc, But that's really a different question (actually one that has been asked and answered countless times). Google is your friend. And [} superuser too. .-) – Alois Mahdal Jan 18 '12 at 19:31
  • @Alois Mahdal Yeah. I thought it would be but I also thought that seemed important information to attach to this question for archival sake. – Sion Jan 19 '12 at 6:21
  • The problem with this approach is that I access several different servers through ssh (not at the same network). I would prefer to have the terminal colors set at the moment of connection. Anyway, I will be copying my configuration to the servers on demand. Thank you. – Edu Jan 20 '12 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.