I'm not sure if this is a problem with my mac, of which I'm a noob with, or if it's a setting of the server I'm sshing into.

What I'm doing is this:

  1. Open a new window in terminal
  2. SSH into a CentOS server. My login shell is bash.
  3. Click on Shell->Edit Title
  4. Change the title and the tab title to abc123. It gets reflected in the terminal title bar as abc123-abc123-ssh-100x24
  5. In the terminal, run 'sudo su' to change user to root. Note the title has now changed to root@blah:/home/myuser-ssh-100x24. If I log out of root, the title name is still this new name.

How do you make the title name stick as abc123 and not change when I su to other users? Thanks in advance for your help.


The title is set from the server you're connecting to. Chances are, /etc/bashrc or a similar file defines PROMPT_COMMAND to set the title. On CentOS 6, it looks like this:

  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
        if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
            PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
[... more of the same ...]

To prevent this, make sure to set PROMPT_COMMAND= in root's and your own bash configuration files on the server you SSH into (e.g. ~/.bashrc).

Alternatively, add PROMPT_COMMAND to /etc/sudoers (env_keep) and /etc/ssh/sshd_config (AcceptEnv) to inherit it from the local system, and set it to a value that does not affect the title bar.

In this specific case, you could also set your Terminal declare a different Terminal, as this is only set for xterm* on CentOS (Terminal » Preferences… » Settings » (Select Profile) » Advanced » Declare Terminal as).

Terminal.app does not seem to allow to lock the title – you're probably expected to change the configuration that sets it as described above. You could always check out a different terminal, such as iTerm. It supports keeping the profile name in the title even the title changes.

And here's a dirty hack to keep your terminal title without changing the configuration of all servers you SSH into:

In the same shell you SSH into your Linux box, before you do that, run the following command:

while true ; do printf "\033]0;%s\007" "My Terminal Title" ; sleep 1 ; done &

This will execute a loop in the background that changes the terminal title to My Terminal Title once a second, overriding any changes performed in your SSH session.

Once you're done, use job control in your shell to stop it (jobs and kill %1 if it's the first job), or fg to bring it to foreground, and cancel with Ctrl-C.

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.