Is there a way to make my terminal (konsole) display different text colors when I'm in an ssh session WITHOUT modifying the remote host's color configuration? Like, maybe automatically switching to a different profile?

Konsole can use these different "profiles"

alt text

I want to basically change to a different profile when in an ssh session. So that instead of the default being green on black, change to black on white or something.

It doesn't necessarily have to use this profile setting. But if xterm or something has a setting to do this that would work too.

The idea is to work on ANY ssh session, not just particular sessions with particular machines.

  • 2
    Konsole, like all KDE applications, can be sent commands through dbus (see Scripting Konsole). The documentation is very sparse, but I think there is unfortunately no command to change the profile of the current tab. Commented Oct 28, 2010 at 21:23
  • It doesn't NECESSARILY have to be by using knsole profiles. I just thought that might be one way. Is there anyway to do this in xterm itself? Or maybe even in the shell?
    – Falmarri
    Commented Oct 31, 2010 at 1:58

3 Answers 3


One possibility, if the terminal supports it, is to use the terminal's Change Color escape sequence. Apparently konsole doesn't support it though. From the Xterm control sequence document (ctlseqs):


Ps = 4 ; c ; spec -> Change Color Number c to the color specified by spec, i.e., a name or RGB specification as per XParseColor. Any number of c name pairs may be given. The color numbers correspond to the ANSI colors 0-7, their bright versions 8-15, and if supported, the remainder of the 88-color or 256-color table.

What this means is that the control sequence \e]4;NUMBER;VALUE\a will change the appearance of color NUMBER. NUMBER is a color number (0–7 for the eight basic colors, 8–15 for the bright versions, and more if the terminal supports more colors). The VALUE is something that XParseColor understands, such as an RGB specification #123456 or an X color name (look for rgb.txt on your machine, or use xcolors to see the possibilities).

For example, the following command changes the basic blue color (color 4) and its bright variant (4+8) to contain some green:

printf '\033]4;4;#004080;12;#0040ff\007'

Note that this changes every character currently displayed in this particular color in the window. There is no way to change the meaning of a color only for subsequently displayed characters; if that's what you want, you'll have to configure each program displaying inside the terminal to use different color numbers when talking to the terminal.

Having this happen exactly when you're typing in an ssh session will be very complicated, but handling the common cases is reasonably simple: use a wrapper around ssh that changes the color palette, then runs ssh, and finally changes the color palette back. Examples of cases this won't handle are suspending the ssh process and running ssh inside screen or tmux.

  • Wouldn't you need to put that in the .bashrc of the remote machine though, since that's the one that draws the shell? He said he's looking for a way to do it without modifying the remote configuration Commented Oct 27, 2010 at 10:48
  • @Michael: I understood that as not needing to modify the color settings of individual applications (as in, not changing $LS_COLORS and face settings in .emacs and filetype settings in .vimrc and so on). If the remote .bashrc must not change, a wrapper around ssh is another possibility. Come to think of it, it's more reliable since you'd have to change the colors back when the ssh session ends. Commented Oct 27, 2010 at 17:38
  • No, I don't want to change the remote machine at all. I'll update my post
    – Falmarri
    Commented Oct 27, 2010 at 19:35

Does Konsole have a place on one of its settings tabs along the lines of "Run a custom command instead of my shell"?

If so, you can do the following (this is what I've set up for my Gnome-Terminal, you may have to tweak slightly for Konsole; I'll be happy to update if there are differences with Konsole):

  1. Create a profile with the color scheme you want.
  2. Check the "run a custom command" box.
  3. Put in ssh [remote host alias] in the "custom command" text box
    • If you want it to act like a local terminal and close the tab when you type exit, then select the "When command exits: Exit the terminal" (or its equivalent)

With that setup, you can simply open a new tab with the selected profile, and it will automatically connect to your SSH session and have the color scheme that you want.

This does, however, have the drawback that it doesn't work for just any SSH connection (as written above, you have to set up a profile for every SSH connection, though you can probably write a script that allows you to enter in the remote host when you open up that profile), and you have to open the profile specifically, unless you set it as your default profile.


The sequence to change the background and foreground colours in xterm (and a few other X11 terminal emulators) are \33]11;black\7 and \33]10;green\7. And there's a xtermcontrol command that makes it easier:

xtermcontrol --bg black --fg green

So you can redefine your ssh command as:

ssh() {
  [ -t 2 ] && xtermcontrol --bg black --fg green
  command ssh "$@"
  [ -t 2 ] && xtermcontrol --bg white --fg black

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .