As you might know, when you ssh to a server from an X terminal (rxvt, gnome-terminal...), ssh changes the window title to reflect user@host, but it does not change it back.

There are many tips how to fix this around the Internets. I'm not asking for another one 1.

What I am looking for is explanation why is it so. So I can learn to live with that. Why ssh does not set the title back?

To put it more FITD way: if vim can do it, why ssh can't?

1 ...unless the explanation is that the problem is caused only by ssh misconfiguration in which case I welcome way to fix that.

  • 2
    ssh doesn't change the terminal name, the remote shell does that, as your local shell set the name in the first place. Since ssh has no idea that terminal names even exist, it couldn't possibly change it back.
    – msw
    Jun 6, 2013 at 16:01

1 Answer 1


The window title in a terminal is set by control characters embedded in the output of whatever is running in the terminal. ssh is oblivious to this as it merely passes whatever characters are generated on the remote end back to the client's stdout. Usually most UNIX/Linux systems which "set the window title" do this by embedding the control characters in the shell's prompt PS1 variable in either in the main /etc/bash_profile or in the user's default $HOME/.bashrc or $HOME/.bash_profile (or whatever configuration file your chosen shell uses). This page describes how to do it in a number of different shells.

So, with that explained, then you log in to a remote machine with this stuff set up, the window title gets set, and the reason the window title doesn't "change back" is probably because your local machine doesn't have these control characters embedded in your local prompt to re-set the window title. In other words, once the window title has been set by these control characters, they don't automatically unset. You have to actually output the control characters again to change it, usually by having them in your local prompt variable.

VIM running on the local machine can query the window title from the X server (by referencing the window ID in $WINDOWID) and save the title to restore it back when it exits. This can be controlled with the VIM options title and titlestring (see :help 'title'). The ssh client simply doesn't seem to do this, again probably because ssh doesn't directly manage the window title at all, it just outputs the characters from the remote shell.

edit: Thanks to Stephane Chazelas in the comments for corrections about VIMs title behavior.

  • 1
    There's no such thing as a different title per alternate screen. vim, when built with X11 support queries the X server for the title of the X terminal emulator (based on the $WINDOWID environment variable (you can watch it restore it to "Firefox" for instance by setting $WINDOWID to the window id of firefox for instance)) or restores it based on the titleold setting otherwise. Some terminals used to allow querying the title via escape sequences, but that was a security vulnerability, so most no longer support it. Jun 6, 2013 at 19:46
  • 1
    xterm allows to save and restore the window and icon titles on a stack with the \e[22;0t and \e[23;0t sequences but I'm not aware that vim uses it though. Jun 6, 2013 at 20:06
  • It's still pretty confusing given that: I use 2 boxes, with PS1 set to basically the same thing except for actual color: one box with X, one without. 1. I log on to the X machine. 2. I open urxvt -- title is not set. 3. I ssh to non-X box -- title is set. o_O Jun 6, 2013 at 22:29
  • Alois: Can you please post the echo "$PS1" output from both servers? Jun 6, 2013 at 22:33
  • 1
    Oh, suddenly it strikes me: It's byobu on the VPS box that keeps setting my title! It's even harder to realize since I so often use byobu option "Run session without byobu", but it sets the title before that. Jun 6, 2013 at 22:34

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.