Terminal displays gibberish but working otherwise

Good day. I installed an update today and my system never actually rebooted. I went and checked everything and got it to boot and then tried to log in via Termius and when I logged in, the terminal looked like the below:

image

When I went to the web interface, everything is working fine as far as I can tell. Tried rebooting, same result. Any feedback on this?

Hi,

The garbled text looks like control characters which add formatting such as the bold and green colour to give the prompt [core-ssh ~]$ .

Best I can guess, is there was a mis-match between the shell, and the terminal emulator and some character got dropped. Being a greybeard Engineer, this used ot happen over modems and serial terminals, so stty sane ^M got used a lot to reset the shell (CONTROL-M is used instead of the direct ENTER or RETURN keys in case of re-mapping).

For the web shell, ^D (CONTROL-D) will close the session, and hit return to start another.

If this is a persistent issue, the $PROMPT_COMMAND env variable has become corrupted - this is what Bash uses to set the prompt. This is usually set in /etc/bashrc, but on HA, it is in /etc/bash/bashrc

Worst case, remote and reinstall Terminal & SSH. (N.B. The web shell is only visible in “Advanced Mode” users. Profile → turn on Advanced Mode.)

(I was going to suggest checking .bash_profile and .tmux.conf, but there’s not much in there by default so they should be fine. If /etc/bash/bashrc is corrupt, you have larger issues than a bad prompt. BACKUP NOW!)

If this helps, :heart: this post!

1 Like

Thank you for your detailed response. I always enjoy learning new stuff. I keep regular backups on my google drive so I’m good there but would like to know, if I wipe the SD card, reinstall from a clean image, and restore from backup, is this error imbedded in the backup and we end up in the same place, or is this a corrupt part of the OS that will be resolved with a fresh installation and restore?

Thanks for your time!

I’ve re-read your post, and want to check if my understanding is correct:

  1. Does logging in via the web-shell give the “normal” prompt [core-ssh ~]$ ?
  2. Is Termius a terminal app running on another device, and using this gives corrpuption?
    If so, the issue is less HA, and more the other device terminal app $TERM terminal type.

In the old days, terminals were hardware devices (CRT screen, keyboard, serial interface, later LAN) and worked differently - e.g. VT100 gave different characters than an xterm. Control characters like bold and colours were very likely to use different control codes. Software terminal emulators are the same - try VT100 or xterm or whatever and see if the \e\w\a disappears.


To answer your question directly…
Q: Will a possible corruption be restored as part of a restore?
A: Almost impossible to be sure, as it depends on what is corrupted (e.g. /etc/bash/bashrc is probably HA core, other items may be seen as user-data).

If the web-shell were corrupted, I’d reinstall this first (start with the minimum damage option).

In this case, it might well not be HA at all, but the term type on a client PC emulator…

Thanks again for responding.

  1. Wow… That was unexpected… When I logged in via the web-shell (I assume you are referring to the Advanced SSH & Web Terminal in the addon section) it looks fine to me and I get the drawing and a normal looking prompt.

  2. Termius is like PuTTY on steroids, so yes, it is a terminal app. I tried running it on PC, and iOS and had the gibberish. I also tried PuTTY and had the same gibberish. Its weird becuase I have always used Termius to SSH into HA and never had an issue. Now, suddenly, I can only use the web-shell. Any suggestions? I would agree with you on Termius being the issue if PuTTY didnt exhibit the same behavior.

Thanks again for your time.

This confirms your issue is more likely to be the $TERM type on the client.

Try fixing the $TERM type on the client (terminal type being emulated - experiment).

I set up a test from a Win10 box using Putty 64-bit and SSH’ing in to HA. The prompt worked fine, and gave:

[core-ssh ~]$ echo $TERM
xterm

Default install of PuTTY 64b, Answerback to ^E: = PuTTY.

After adding a ssh-rsa key to Authorized Keys, I can also SSH in from a Linux box fine ($TERM=xterm-256color).

Try reinstalling PuTTY? Try reinstalling the HA Terminal & SSH Add-On?

If this helps, :heart: this post!

The strange Home Assistant CLI prompt, i.e. …

\[\e]0;\u@\h:\w\a\]\W $

…is the result of a setting of the add-on “Advanced SSH & Web Terminal”.

Here is how to change it:
Open Settings → Add-ons → select Advanced SSH & Web Terminal → Configuration tab → disable zsh

What I do not understand so far is that I actually do use a ZSH terminal (on MacOS) and its color mode is working correctly (i.e. the command ls -al generates colored output) but the control sequences of the HA prompt are not interpreted at all. Maybe somebody else can enlighten us here.