When I am SSH'ed into any one of my Linux devices, the title bar on Terminator displays user@hostname, where hostname is the computer I am SSHing from, rather than the computer I am SSH'ed into (i.e. the title bar mirrors $PS1 from the local device rather than the remote device). This makes it very confusing if I am SSH'ed into all 4 computers at the same time and can't see their prompts (as all their title bars are identical!).

How can I have Terminator display the correct hostname?

marked as duplicate by Gilles bash Mar 11 '16 at 23:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • printf "\033];%s\07\n" "${USER}@$(hostname)" maybe ? – MelBurslan Mar 11 '16 at 18:40
  • what distro are you using on that computers? All my computers I ssh to do that with default configuration and I don't think it is needed to create such wild stuff as described in the answer. – Jakuje Mar 11 '16 at 19:31
  • Chromixium (which is based on Ubuntu) on 3 of them, Peppermint Linux 6 on the other one. – Andy Forceno Mar 11 '16 at 19:38

While it's certainly possible for users to customize their prompt (and make that update the terminal's title), most use the default shell behavior.

It sounds as if your local machine is setting the title string as a side effect of your prompt, and that the remote machines are not changing the title.

Given that, you can update the title without interference by the remote machines, e.g., using a wrapper script for ssh such as this:

# trim parameters, leaving just the last (user@hostname or just hostname)
title=$(echo "$*" | sed -e 's/^.* //')
printf '\033]0;%s\007' "$title"
/usr/bin/ssh "$@"

and putting that in your executable path ahead of /usr/bin, you could call that "ssh" and have it set your title string as you visit each remote machine. After exiting ssh, your local prompt would reset the title string back to the local machine.

In a followup comment, OP indicated that the connections are made to an IP-address. If the remote machine has a hostname, then it would make the procedure clearer to use that, or (if not in DNS) collect the hostnames into the local machine's /etc/hosts. Ultimately, DNS is the way to go...

For reference:

  • Maybe I did this wrong, because although it works, it sets the title to whatever comes after the ssh command. For instance, the title when logged into my one machine now says "-p 22223" rather than "user@hostname". Although that is an improvement, it's not the expected behavior. – Andy Forceno Mar 11 '16 at 19:49
  • Sorry - I was making a simple script, assuming the case where one does ssh hostname or ssh user@hostname. For your case, I'd have an /etc/hosts file so I could refer to everything by name, and amend the script to ignore options/values such as the -p22223. – Thomas Dickey Mar 11 '16 at 19:51
  • Ah, I forgot about /etc/hosts. Adding my machines to that did the trick. – Andy Forceno Mar 11 '16 at 20:23
  • And if I wanted to display user@host $pwd, how can I do that? I tried adding "$pwd" after "$title", but that just replaces $title. – Andy Forceno Mar 11 '16 at 21:12
  • If you want the working directory on the remote machine to show in the title, you'll have to configure the PS1 string on the remote machines. The Batch Prompt HOWTO is a good place to start. – Thomas Dickey Mar 11 '16 at 21:18

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