Monday, May 6, 2024
24
rated 0 times [  24] [ 0]  / answers: 1 / hits: 37195  / 2 Years ago, mon, december 6, 2021, 12:12:46

Is it possible to automatically change the color of the terminal based on which server I am connected to through SSH?



For instance, when I fire up the terminal it has the standard colors defined under my profile.
Then I ssh to ssh.example.com and the color changes to black & green instead.
Then I exit the session and the color returns to the standard color theme.



I know that you could do this manually. But I'm looking for an automated way.


More From » command-line

 Answers
4

Yes, you can by changing the PS1 value in .bashrc file on every hostname where you are connecting with ssh.



See this answer to view how to costumize as you like the bash changing the PS1 value.



ssh colored



On my machine (radu@Radu) I have in .bashrc:



PS1='${debian_chroot:+($debian_chroot)}[033[01;35m]u@h[033[00m]:[033[01;34m] w[033[01;37m] > '


On the hosted machine (radu@ubuntu) I have:



PS1='${debian_chroot:+($debian_chroot)}[033[01;35;40m]u@ubuntu[033[00;40m]:[033[01;34;40m] w[033[01;32;40m] > '

[#30658] Tuesday, December 7, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
enefiama

Total Points: 43
Total Questions: 125
Total Answers: 102

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;