9

So you want to change terminal colors and resetting them back on exit? It's possible!

Thanks to .ssh/config, alias and setterm.

  • I know, we have tons of such questions, but I just did not found any simple as my current version. Also to those, who can expand my answer with details, pls expand it. Then after more detailed version we can accept it. – gaRex Jun 5 '13 at 8:13
15

.bash_aliases

function ssh_alias() {
    ssh $@;
    setterm -default -clear rest;
}

alias ssh=ssh_alias

/etc/ssh/ssh_config

# Make sure you have this line there:
PermitLocalCommand yes

.ssh/config

Host your.production.host
  User root
  LocalCommand setterm -term linux -back red -fore white -clear rest

Now you can in bash:

some command
# all in default colors
ssh your.production.host
# colors changed
# ....
exit
# colors changed back! yeea!
  • This is exactly what I was looking for after googling it for hours. – MonkeyMonkey Nov 5 '14 at 16:54
  • Finally, after hours of search, I found exactly what I wanted. Thank you gaRex :) – Amal Murali Jun 14 '16 at 14:12
  • 1
    When i login I get the following error: setterm: argument error: 'rest' Any idea why? – linello Aug 29 '18 at 9:07
  • man setterm, search there --clear. In mine version it exists. – gaRex Aug 29 '18 at 13:15
  • Can anyone add description of the changes done – Nilesh Feb 4 at 5:43
3

(read gaRex's response first)

setterm has changed the arguments in recent versions:

.bash_aliases

function ssh_alias() {
    ssh $@;
    setterm --default --clear all;
}

alias ssh=ssh_alias

.ssh/config

Host myproject.pro
    HostName myproject.com
    User root
    IdentityFile ~/.ssh/myproject
    LocalCommand setterm --term linux --background white --foreground black --clear all

You can still use:

--clear rest

You can reload .bash_aliases file with:

exec bash

More info:

man setterm
  • This is a 3 year old question and your answer is similar to the one already answered – SeanClt Mar 26 '16 at 20:52
  • 2
    yep... I only wanted to add more info. Could be a response to gaRex's response. – JoniJnm Mar 26 '16 at 21:58
  • yep i am with and clearly understand you want to help and we want folks like you – SeanClt Mar 26 '16 at 21:59
  • 1
    click on "improve this answer" in my initial answer. – gaRex Jun 15 '16 at 6:26

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.