OpenSSH via powershell - vi turns prompt blue

5,980

Solution 1

Powershell is not a terminal emulator and thus will get all excited about the according remote flow control and visual control character that.

As long as you are planning to use ssh in a script, you wouldn't care less about fishy colours, they will not show in the output. What does possible happen though is that you end up with some garbled characters. Like

However, if this is an interactive shell, consider using a terminal emulator like putty.

Solution 2

this was apparently a bug in the Windows Console Host.

The relevant discussion is here on the Powershell-OpenSSH github repo.

According to the maintainers, Windows 1809 (the 2018 Fall update) has the fix for this issue.

Share:
5,980

Related videos on Youtube

p0lar_bear
Author by

p0lar_bear

Script kiddie of a few programming/scripting languages with a computer science degree in progress. I know my way around Visual Basic.NET, C#.NET, PHP, HTML, XHTML, CSS2, and MySQL. I know things about Perl, C++, UNIX Shell Script, Windows Batch, and Transact-SQL, but not as well as the first list of languages.

Updated on September 18, 2022

Comments

  • p0lar_bear
    p0lar_bear over 1 year

    I'm on Windows 10, using Win32-OpenSSH via Powershell to connect to a CentOS 7 machine on my network.

    If I launch vi on a new file, or on occasion open other files, any and all new text in my window turns blue.

    enter image description here

    This continues until I close the Powershell window.

    Any idea why this is happening, and if there's a workaround that doesn't involve using a different ssh client or environment? I understand I can just use a "proper" terminal emulator like PuTTYm, but my question is whether or not there's a known fix for this particular scenario.

    • Kamil Maciorowski
      Kamil Maciorowski almost 6 years
      Does it happen when you use another client (e.g. PuTTY) to connect?
    • user1686
      user1686 almost 6 years
      Are you using vim, neovim, nvi, or ex-vi?
    • p0lar_bear
      p0lar_bear almost 6 years
      @KamilMaciorowski I haven't tried another terminal emulator. However, this doesn't happen when I'm using the machine directly, i.e. by connecting to it via the Hyper-V manager.
    • p0lar_bear
      p0lar_bear almost 6 years
      @grawity I have no idea off the top of my head. As the buffer shows I'm executing vi and this is a barely-modified CentOS 7 minimal install, I'm assuming this is just vanilla vi. And I do remember trying to execute vim and getting a "command not found".
  • p0lar_bear
    p0lar_bear almost 6 years
    I'm more than aware that the Windows console isn't and does not attempt to emulate a VT100 TTY. However, Microsoft's flavor of the OpenSSH client includes a VT100 interpreter and it's said that it can handle most TTY scenarios, with the caveat that some interactive *nix applications have some issues. github.com/PowerShell/Win32-OpenSSH/wiki/… The question was asking if there was any sort of known workaround for this, i.e. if other WinOpenSSH users encountered this, or if it's happened to other TTY emulators.
  • Kaveh Vahedipour
    Kaveh Vahedipour almost 6 years
    The problem is not the ssh client, i.e. openssh. The problem is that cmd or powershell receive the control signs that manipulate the colors etc. in the client terminal like \[\e]0; and instead of turning the font green just screws up. In other words, if you used the openssh client in its own UI window you're gonna be fine. Btw, the same garbage will show if you use plink.exe from PuTTY in a cmd shell. I'd really appreciate, if you accepted the answer, if this helped you, as some jackass decided to downvote the correct answer.
  • p0lar_bear
    p0lar_bear almost 6 years
    It's no secret that Windows and *nix historically don't interoperate well. Microsoft is aware of this and they have a fork of OpenSSH made specifically for use with cmd/powershell, which I am using. This is indeed an issue with this specific ssh client, as the integrated VT100 interpreter likely isn't handling some control codes in a fashion that result in the expected output. As you can see in my screenshot, I'm not getting "garbage" output as if I was running a script or binary intended for an ANSI terminal with no further processing.
  • Kaveh Vahedipour
    Kaveh Vahedipour almost 6 years
    I'd really appreciate if you would accept my answer, then.
  • p0lar_bear
    p0lar_bear almost 6 years
    No. In addition, said "jackass" was me, thank you, as this answer reads much like bashing Windows for the sake of bashing Windows. Your attitude towards the downvote (i.e. calling me a jackass and asserting that your answer is THE correct answer) reinforces this perception. Though on reflection, I will concede I wasn't clear. I will reverse the downvote because I realize I need to rephrase my question as I wanted insight as to why this happens, and to know if there was a workaround that wasn't "just use PuTTY lol", and it seems my intent wasn't conveyed.
  • p0lar_bear
    p0lar_bear almost 6 years
    ...And I can't undo the vote unless you edit the answer. Figures. :/
  • Kaveh Vahedipour
    Kaveh Vahedipour almost 6 years
    With all due respect, I really don't see, where the answer is bashing for bashing windows. I am 47 and beyond those years. The first line just says that powershell is not a terminal emulator. It is not meant to be one, ever. The rest is "consider using ...". Anyway many thx.
  • p0lar_bear
    p0lar_bear almost 6 years
    Thank you, that answer reads much better. I will consider accepting this as the answer if nobody else comes along soon and posts an answer that has a workaround/fix. Apologies for the crossed signals.