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 xterm*) if [ -e /etc/sysconfig/bash-prompt-xterm ]; then PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm else PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "$" "$" "$"' fi ;; [... more of the same ...] esac fi
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
.