Skip navigation

Bug in terminal. Wrong host name displayed in title bar in some cases.

1650 Views 9 Replies Latest reply: Nov 28, 2012 4:11 AM by BobHarris RSS
msloan1 Calculating status...
Currently Being Moderated
Oct 4, 2012 6:17 PM

Steps to repoduce.

1) open terminal.

2) ssh into host A

3) exit host A

4) ssh into host B

5) exit host B

6) ssh back to host A

7) vi a file (e.g. vi touchfile)

8) Note that title bar of the terminal window shows host B, when in fact you are editing a file on host A. 

9) quit vi note the title bar changes back to the correct host.

Terminal , OS X Mountain Lion (10.8.2)
  • BobHarris Level 6 Level 6 (12,510 points)

    Terminal does not really know you are logging into a remote system.  If anything, something on the remote system is sending escape codes that change the Terminals title bar.  Vim (what is really invoked by vi) will send those escape codes.


    echo -e "\e]0;`hostname`\007"


    If you put something like this in your remote hosts shell initialization file, it will always set your title bar to the host you are ssh'ing into.  Depending on the shell you us on those remote systems, you may need to use different syntax for the echo command.  What I have shown is for 'bash'

  • Gnarlodious Level 4 Level 4 (3,220 points)
  • etresoft Level 7 Level 7 (23,905 points)

    What do you have set for Terminal > Preferences > Settings > Window > Title ?


    Are you, or any of your login shells on any of those machines, emitting any escape codes?


    I don't see any built-in settings to do this. You must be relying on some of those escape sequences. That is a popular trick using bash preexec commands, but not reliable.

  • VikingOSX Level 5 Level 5 (4,710 points)

    This previous post from July 18 offers some hints on setting/unsetting the SSH host name in the OS X Terminal Window or Tab name.

  • Lowry76 Calculating status...

    I just got my new MBP (10.8) and after setting everything up I experience the same problem even faster.


    1. open terminal ( title = bash )

    2. ssh with username@host ( title = username@host: )

    3. quit ssh session ( title = username@host: )


    The title stays like this until I ssh to another host and then changes to the new username@host.

    This only happens on my new 10.8 MBP and but not on my other 10.5 MBP. Not sure if it's the or the OS itself ... but still annoying

  • BobHarris Level 6 Level 6 (12,510 points)

    See my earlier response: <> in this thread.


    Terminal does not know you ssh'ed and it does not know that you exit'ed from the ssh session.  So the Terminal cannot know to change your title.


    If this worked on another system, then it was the 'bash' shell doing this, or the old ssh as it was exiting from the session reset the title.


    As far as I can see, those are the only to possible ways the title could have been reset to 'bash' after the ssh session terminated.


    If you wish to control your title, you can modify your 'bash' PS1 prompt to include an escape sequence.


    Starting with.bash_profile (create it if it does not exist, unless you have a .profile, then use that instead), you will need to create your own PS1 variable




    The \e]0;bash\007 will tell the Terminal to set 'bash' as your title every time bash issues a prompt.  So when you return from your ssh session, you will get a bash prompt and it will reset your Terminal title.


    The \[...\] tells bash that the stuff in between is not displayed in the prompt, so command line editing is done correctly when lines are longer than the width of the terminal.


    the $PS1 just appends your current prompt to the end of the escape sequence that changes your title.


    You can replace 'bash' in the title escape string with anything you like.  For example you could put \u@\h there to substitute your username@hostname for your local system:


    MacBook Pro, Mac OS X (10.7.5), 27&quot; iMac, MacBook, MacMini, etc...
  • Lowry76 Level 1 Level 1 (0 points)

    Thank you for the answer and the work-around.

    I agree that it's most likely not the but because there was a thread already I didn't want to open a new one. Maybe I should have made a new one  "Bug in XCode/shell/ssh" because (at least from my point of view) this is a bug and not a feature. None of the linux derivates I used in the last years showed a similar behavior (not even cygwin consoles). Either the console title should stay as is whatever session you open or, in case it changes the title, it should change it back when the session is closed. But changing it only when a session is opened? ...


    Anyways, maybe someone will realize and change it in the next version of whatever script is responsible for this

  • BobHarris Level 6 Level 6 (12,510 points)

    In general it is better to open your own thread, as you then get to control the discussion and award credit for answers you like.


    There is one other possibility. The remote system issued the title escape sequence in the /etc/profile or similar system wide shell initialization script.


    And of course your own remote shell initialization script could have issued the title escape sequence, especially if the first copy is provided by your local UT group and you did not suspect it existed.


More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.