PowerShell / Win32-OpenSSH

Win32 port of OpenSSH
7.42k stars 759 forks source link

garbled characters #1768

Open Tancen opened 3 years ago

Tancen commented 3 years ago

Troubleshooting steps https://github.com/PowerShell/Win32-OpenSSH/wiki/Troubleshooting-Steps

Terminal issue? please go through wiki https://github.com/PowerShell/Win32-OpenSSH/wiki/TTY-PTY-support-in-Windows-OpenSSH

Please answer the following

"OpenSSH for Windows" version ((Get-Item (Get-Command sshd).Source).VersionInfo.FileVersion) OpenSSH_for_Windows_8.1p1, LibreSSL 2.9.2

Server OperatingSystem ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion\" -Name ProductName).ProductName) Microsoft Windows [Version 10.0.19042.867] x64

Client OperatingSystem Microsoft Windows [Version 10.0.19042.867] x64

What is failing ssh client got garbled characters both in win32-openssh, git-scm, linux

image

image image

Expected output

Actual output

bagajjal commented 3 years ago

@Tancen - Please share sshd server side logs with DEBUG3 enabled.

bagajjal commented 3 years ago

@Tancen - What is the ssh server operating system? Is it windows 10 or windows server 2019? Also can you try " dir e:\ " instead of " ls e:\ ". Please note the default shell is cmd.exe. cmd.exe doesn't understand "ls" as a command.

Tancen commented 3 years ago

debug2: load_server_config: filename PROGRAMDATA\ssh/sshd_config debug2: load_server_config: done config len = 251 debug2: parse_server_config: config PROGRAMDATA\ssh/sshd_config len 251 debug3: PROGRAMDATA\ssh/sshd_config:38 setting AuthorizedKeysFile .ssh/authorized_keys debug3: PROGRAMDATA\ssh/sshd_config:76 setting Subsystem sftp sftp-server.exe debug3: checking syntax for 'Match Group administrators' debug1: sshd version OpenSSH_for_Windows_8.1, LibreSSL 2.9.2 debug1: private host key #0: ssh-rsa SHA256:kR7kqIqPYwYOXA6vdKwlej5OwawbNv7wXpkHhPV55fI debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:R5142TaQSmZiiXJn+mpQ8vRTkFkaBal8OeEj2Oq2YHk debug1: private host key #2: ssh-ed25519 SHA256:PO+I+/XzLgDDIEuwd+eioXHZD+im9bOvBtOBQIEYP+8 debug1: rexec_argv[0]='D:\OpenSSH\OpenSSH-Win64\sshd.exe' debug1: rexec_argv[1]='-E' debug1: rexec_argv[2]='D:\OpenSSH\OpenSSH-Win64\log.txt' debug1: rexec_argv[3]='-ddd' debug2: fd 4 setting O_NONBLOCK debug3: sock_set_v6only: set socket 4 IPV6_V6ONLY debug1: Bind to port 22 on ::. Server listening on :: port 22. debug2: fd 5 setting O_NONBLOCK debug1: Bind to port 22 on 0.0.0.0. Server listening on 0.0.0.0 port 22. debug3: fd 6 is not O_NONBLOCK debug1: Server will not fork when running in debugging mode. debug3: send_rexec_state: entering fd = 9 config len 251 debug3: ssh_msg_send: type 0 debug3: send_rexec_state: done Connection from 127.0.0.1 port 60606 on 127.0.0.1 port 22 debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1 debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_8.1 debug1: match: OpenSSH_for_Windows_8.1 pat OpenSSH* compat 0x04000000 debug2: fd 6 setting O_NONBLOCK debug3: spawning "D:\OpenSSH\OpenSSH-Win64\sshd.exe" -E D:\OpenSSH\OpenSSH-Win64\log.txt -ddd -y debug2: Network child is on pid 632 debug3: send_rexec_state: entering fd = 5 config len 251 debug3: ssh_msg_send: type 0 debug3: send_rexec_state: done debug3: ssh_msg_send: type 0 debug3: ssh_msg_send: type 0 debug3: preauth child monitor started debug1: list_hostkey_types: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519 [preauth] debug3: send packet: type 20 [preauth] debug1: SSH2_MSG_KEXINIT sent [preauth] debug3: receive packet: type 20 [preauth] debug1: SSH2_MSG_KEXINIT received [preauth] debug2: local server KEXINIT proposal [preauth] debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1 [preauth] debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519 [preauth] debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com [preauth] debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com [preauth] debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 [preauth] debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 [preauth] debug2: compression ctos: none,zlib@openssh.com [preauth] debug2: compression stoc: none,zlib@openssh.com [preauth] debug2: languages ctos: [preauth] debug2: languages stoc: [preauth] debug2: first_kex_follows 0 [preauth] debug2: reserved 0 [preauth] debug2: peer client KEXINIT proposal [preauth] debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c [preauth] debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa [preauth] debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com [preauth] debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com [preauth] debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 [preauth] debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 [preauth] debug2: compression ctos: none,zlib@openssh.com,zlib [preauth] debug2: compression stoc: none,zlib@openssh.com,zlib [preauth] debug2: languages ctos: [preauth] debug2: languages stoc: [preauth] debug2: first_kex_follows 0 [preauth] debug2: reserved 0 [preauth] debug1: kex: algorithm: curve25519-sha256 [preauth] debug1: kex: host key algorithm: ecdsa-sha2-nistp256 [preauth] debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: compression: none [preauth] debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: compression: none [preauth] debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth] debug3: receive packet: type 30 [preauth] debug3: mm_sshkey_sign entering [preauth] debug3: mm_request_send entering: type 6 [preauth] debug3: mm_sshkey_sign: waiting for MONITOR_ANS_SIGN [preauth] debug3: mm_request_receive_expect entering: type 7 [preauth] debug3: mm_request_receive entering [preauth] debug3: mm_request_receive entering debug3: monitor_read: checking request 6 debug3: mm_answer_sign debug3: mm_answer_sign: KEX signature 0000024836421C50(99) debug3: mm_request_send entering: type 7 debug2: monitor_read: 6 used once, disabling now debug3: send packet: type 31 [preauth] debug3: send packet: type 21 [preauth] debug2: set_newkeys: mode 1 [preauth] debug1: rekey out after 134217728 blocks [preauth] debug1: SSH2_MSG_NEWKEYS sent [preauth] debug1: Sending SSH2_MSG_EXT_INFO [preauth] debug3: send packet: type 7 [preauth] debug1: expecting SSH2_MSG_NEWKEYS [preauth] debug3: receive packet: type 21 [preauth] debug1: SSH2_MSG_NEWKEYS received [preauth] debug2: set_newkeys: mode 0 [preauth] debug1: rekey in after 134217728 blocks [preauth] debug1: KEX done [preauth] debug3: receive packet: type 5 [preauth] debug3: send packet: type 6 [preauth] debug3: receive packet: type 50 [preauth] debug1: userauth-request for user git service ssh-connection method none [preauth] debug1: attempt 0 failures 0 [preauth] debug3: mm_getpwnamallow entering [preauth] debug3: mm_request_send entering: type 8 [preauth] debug3: mm_getpwnamallow: waiting for MONITOR_ANS_PWNAM [preauth] debug3: mm_request_receive_expect entering: type 9 [preauth] debug3: mm_request_receive entering [preauth] debug3: mm_request_receive entering debug3: monitor_read: checking request 8 debug3: mm_answer_pwnamallow debug2: parse_server_config: config reprocess config len 251 debug3: checking match for 'Group administrators' user git host 127.0.0.1 addr 127.0.0.1 laddr 127.0.0.1 lport 22 debug3: LsaLogonUser Succeeded (Impersonation: 0) debug1: user git does not match group list administrators at line 84 debug3: match not found debug3: mm_answer_pwnamallow: sending MONITOR_ANS_PWNAM: 1 debug3: mm_request_send entering: type 9 debug2: monitor_read: 8 used once, disabling now debug2: input_userauth_request: setting up authctxt for git [preauth] debug3: mm_inform_authserv entering [preauth] debug3: mm_request_send entering: type 4 [preauth] debug2: input_userauth_request: try method none [preauth] debug3: user_specific_delay: user specific delay 0.000ms [preauth] debug3: ensure_minimum_time_since: elapsed 1.951ms, delaying 3.365ms (requested 5.316ms) [preauth] debug3: mm_request_receive entering debug3: monitor_read: checking request 4 debug3: mm_answer_authserv: service=ssh-connection, style= debug2: monitor_read: 4 used once, disabling now debug3: userauth_finish: failure partial=0 next methods="publickey,password,keyboard-interactive" [preauth] debug3: send packet: type 51 [preauth] debug3: receive packet: type 50 [preauth] debug1: userauth-request for user git service ssh-connection method keyboard-interactive [preauth] debug1: attempt 1 failures 0 [preauth] debug2: input_userauth_request: try method keyboard-interactive [preauth] debug1: keyboard-interactive devs [preauth] debug1: auth2_challenge: user=git devs= [preauth] debug1: kbdint_alloc: devices '' [preauth] debug2: auth2_challenge_start: devices [preauth] debug3: user_specific_delay: user specific delay 0.000ms [preauth] debug3: ensure_minimum_time_since: elapsed 0.000ms, delaying 5.316ms (requested 5.316ms) [preauth] debug3: userauth_finish: failure partial=0 next methods="publickey,password,keyboard-interactive" [preauth] debug3: send packet: type 51 [preauth] debug3: receive packet: type 50 [preauth] debug1: userauth-request for user git service ssh-connection method password [preauth] debug1: attempt 2 failures 1 [preauth] debug2: input_userauth_request: try method password [preauth] debug3: mm_auth_password entering [preauth] debug3: mm_request_send entering: type 12 [preauth] debug3: mm_auth_password: waiting for MONITOR_ANS_AUTHPASSWORD [preauth] debug3: mm_request_receive_expect entering: type 13 [preauth] debug3: mm_request_receive entering [preauth] debug3: mm_request_receive entering debug3: monitor_read: checking request 12 debug3: mm_answer_authpassword: sending result 1 debug3: mm_request_send entering: type 13 Accepted password for git from 127.0.0.1 port 60606 ssh2 debug1: monitor_child_preauth: git has been authenticated by privileged process debug3: mm_get_keystate: Waiting for new keys debug3: mm_request_receive_expect entering: type 26 debug3: mm_request_receive entering debug3: mm_get_keystate: GOT new keys debug3: mm_auth_password: user authenticated [preauth] debug3: user_specific_delay: user specific delay 0.000ms [preauth] debug3: ensure_minimum_time_since: elapsed 9.747ms, delaying 0.885ms (requested 5.316ms) [preauth] debug3: send packet: type 52 [preauth] debug3: mm_request_send entering: type 26 [preauth] debug3: mm_send_keystate: Finished sending state [preauth] debug1: monitor_read_log: child log fd closed debug3: spawning "D:\OpenSSH\OpenSSH-Win64\sshd.exe" -E D:\OpenSSH\OpenSSH-Win64\log.txt -ddd -z User child is on pid 9408 debug3: send_rexec_state: entering fd = 7 config len 251 debug3: ssh_msg_send: type 0 debug3: send_rexec_state: done debug3: ssh_msg_send: type 0 debug3: ssh_msg_send: type 0 debug3: ssh_msg_send: type 0 debug3: ssh_msg_send: type 0 debug3: ssh_msg_send: type 0 debug3: mm_request_receive entering debug1: do_cleanup

Tancen commented 3 years ago

@bagajjal The ssh server operating system is Windows 10 Pro, Version 10.0.19042.867, 64-bit It's garbled characters aslo on command 'dir e:'

image

But, If logged in be before running command 'dir e:', It's well image

By the way, ssh server shutdown on the session exited when start parameters appended “-E D:\OpenSSH\OpenSSH-Win64\log.txt -ddd” and ssh server running as Windows service.

bagajjal commented 3 years ago

@Tancen - It's expcted. ssh user@ip <_cmd_> ---->> This is non-interactive. In this case, sshd.exe executes (C:\windows\system32\cmd.exe /c ). It all depends on chcp setting on cmd.exe.

Tancen commented 3 years ago

@bagajjal I am not sure that the problem is around the code page. I tried to change the code page before executing the command, but still garbled characters.

image

image

image

Tancen commented 3 years ago

And it's not good to work for git. I don't know what is the means of git reply from a Windows SSH Server. Such as this: image

bagajjal commented 3 years ago

@Tancen - Changing the chcp of the terminal where you execute ssh client doesn't work. As I explained earlier, sshd.exe executes the command in a new process "C:\windows\system32\cmd.exe /c < cmd >". This is a new background cmd.exe.

You should have the chcp setting at a system level so new cmd.exe gets this setting.