terminal: 🐛 Strange bug with pasting sudo password via SSH on Linux 🐧

Windows Terminal version

1.15.2713.0

Windows build number

10.0.22621.608

Other Software

kmatuszak@ubuntu:~$ bash --version
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)

kmatuszak@ubuntu:~$ sudo -V
Sudo version 1.8.31
Sudoers policy plugin version 1.8.31
Sudoers file grammar version 46
Sudoers I/O plugin version 1.8.31

kmatuszak@ubuntu:~$ ssh -V
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f  31 Mar 2020

kmatuszak@ubuntu:~$ uname -r
5.15.0-48-generic

kmatuszak@ubuntu:~$ lsb_release -sd
Ubuntu 20.04.5 LTS

Steps to reproduce

  1. Connect to an Ubuntu server with password set to HtJy*&fPMS4@K84C$RJfFT9*$#SR4E52 via SSH using Windows Terminal
  2. Authenticate using your username and password by pasting the password, this will work fine
  3. Try to run any sudo command which will ask for your sudo password, for example: sudo apt update && sudo apt upgrade -y
  4. Paste your sudo password either by CTRL+V or CTRL+SHIFT+V

Expected Behavior

Password should be accepted, but it is not:

kmatuszak@ubuntu:~$ sudo apt update && sudo apt upgrade -y
[sudo] password for kmatuszak:
Sorry, try again.
[sudo] password for kmatuszak:

Actual Behavior

Password is not accepted either if pasted by CTRL+V or CTRL+SHIFT+V, but it works fine when typed by hand. Also password is accepted just fine if pasted in PuTTY. Other passwords also work just fine if pasted in Windows Terminal. The same password works just fine for initial authentication when connecting to an SSH server, but not for authenticating when running sudo.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@j4james

You can try manually disabling bracketed paste mode by executing printf "\e[?2004l". Although that assumes there isn’t something in your shell that is constantly re-enabling that mode.

Thanks, it seem to work on my side, I tried the bind method for the current session and it didn’t work. (bind 'set enable-bracketed-paste off')

But adding this set enable-bracketed-paste off to my $HOME/.inputrc and then closing and re-opening a new terminal worked… 👍👍

This should have been fixed by #14345, no?

Those of you that are seeing pasted text surrounded by ^[[200~ and ^[[201~, that is because your shell (or perhaps some application or plugin) has enabled bracketed paste mode.

This might be the OP’s problem too. When you’re attempting to connect to the server, bracketed paste mode assumedly wouldn’t be enabled, so you could paste the password without any problem. But if something enables bracketed paste mode after you’ve logged in, then any future attempt to paste the password could fail. You can probably confirm that by trying to paste into showkey -a since that’ll show you any escape sequences surrounding the text.

You can try manually disabling bracketed paste mode by executing printf "\e[?2004l". Although that assumes there isn’t something in your shell that is constantly re-enabling that mode.

Disabling bracketed paste does solve the issue, at least for the current ssh session. I wonder why I never had this problem before with Windows Terminal.