Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

right now I am using an one-line perl code to change titles of my terminal bars,


but every time after I ssh to another remote machine, the title will be modified by the host (by which I'm not particularly bothered). But after I exit from the connection, the modified title remains. Is there a way to fix this? essentially I want a fixed title for my terminals when operating locally.

I primarily use xfce terminal and terminator under either CentOS or Debian. Thanks.


Another subtlety is that, rather having all terminals the same name, I would prefer to have the freedom to edit their titles on-the-fly but only forbid SSH session from modifying what I edited.

share|improve this question
up vote 5 down vote accepted

I don't know about window titles, but I have been trying to have my system do something on terminating a ssh session—actually, after terminating a ssh session. In short: it doesn't work like that. Basically you have three choices:

  1. Write a wrapper around ssh, i.e., an executable shell script named ssh that takes precedence over /usr/bin/ssh in your $PATH which contains the line exec /usr/bin/ssh $@ somewhere in its middle. This enables you to have your shell do some stuff before and after the effective ssh binary is run, while keeping th eoverhead to a minimum.

  2. Write a patch against the SSH sources of your choice to provide you a cleanup hook that executes a shell command passed via commandline or some config-setting. That's what we want.

  3. Have PROMPT_COMMAND evaluate the output of history. Basically a more generic and more ugly approach to 1.

share|improve this answer
basically i just wrote a simple script to grab the current title and save it before SSH session, then recover the title afterwards. – nye17 Jun 15 '12 at 19:04
@nye17 Can you post your solution script that you used ? – Reg Mem Jul 29 '14 at 18:28

ADD these lines to ~/.bashrc

# If this is an xterm set the title to user@host:dir
case "$TERM" in
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"


works well with debian based linuxes

share|improve this answer
Thanks, that is useful. – nye17 Aug 19 '12 at 16:08
IT doesn't set the title though... – Bananguin Jul 29 '14 at 19:55
It usually works better to use PROMPT_COMMAND instead of using PS1, since you don’t have to include the \[ \] bracketing and it can eliminate some quoting. – Chris Page Oct 25 '14 at 0:41

Configure your local shell dotfile (e.g. $PROMPT_COMMAND in ~/.bashrc) to set the terminal title appropriately, using the same mechanism.

For example:

export PROMPT_COMMAND="printf '\e]0;bash\7\n'"
share|improve this answer
1. prompt_command has nothing to do the title of your terminal window, right? I have prompt_command set up but only for the prompt. 2. I still need a mechanism to remember and activate my local setting after exiting the ssh logging. – nye17 Jun 15 '12 at 4:02
The prompt command simply emits the necessary escape sequence for your terminal to rename its title bar. :) – Kuba Ober Jun 15 '12 at 4:03
but I also want the freedom to rename whatever terminal I want, rather than having every single session the same name. In practice, I basically edit the terminal title manual and hope that terminal to stay having fixed title even after SSH login/logout. Does it make sense? – nye17 Jun 15 '12 at 5:23
So then put the desired title in a variable, and output that. – Ignacio Vazquez-Abrams Jun 15 '12 at 6:08

One solution is to change the terminal variable to vt100 before ssh'ing, e.g. run

export TERM=vt100

This works because usually initialization scripts look at the terminal variable and only change it title it it's xterm. You lose alternate screens, colors and maybe some other fancy features you may or may not appreciate.

If you want to keep the local terminal as xterm, alias ssh to change the terminal variable on the fly, like

alias ssh='TERM=vt100 /usr/bin/ssh'
share|improve this answer

I fixed this issue by adding this to my PS1 in my .bashrc file.


Therefore the whole line looks like this(I've customized my PS!:

export PS1='\[\e]2;\u@\H:\w\a\]\n($LOGNAME@$HOSTNAME) \t\n[$PWD]: '

I hope that helps others.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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