Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key created with WSL Linux 'Invalid Format' #1481

Closed
Greenwolf opened this issue Oct 21, 2019 · 5 comments
Closed

Key created with WSL Linux 'Invalid Format' #1481

Greenwolf opened this issue Oct 21, 2019 · 5 comments

Comments

@Greenwolf
Copy link

"OpenSSH for Windows" version

PS C:\Windows\system32> ssh -V
OpenSSH_for_Windows_8.0p1, LibreSSL 2.6.5

Server OperatingSystem
Linux myhost.mydomain.com 4.19.0-kali4-amd64 #1 SMP Debian 4.19.28-2kali1 (2019-03-18) x86_64 GNU/Linux

Client OperatingSystem
Microsoft Windows [Version 10.0.18362.418]

What is failing
After creating a SSH key on WSL Kali Linux, I move the keys to C:\Users\me.ssh

PS C:\Users\me\.ssh> dir


    Directory: C:\Users\me\.ssh


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       21/10/2019     21:33           2654 id_rsa
-a----       21/10/2019     19:54            578 id_rsa.pub
-a----       21/10/2019     20:34            551 known_hosts

When connecting to the server, it never prompts me for my passphrase, and the output seems to show that the id_rsa key is in an invalid format.

It should be noted i have tried this with id_rsa and id_rsa.pub both converted to Linux EoL mode and Windows EoL mode with Notepad++, as suggested in this issue (#1315). However both have the same output.

Expected output

The expected output should prompt the user for the passphrase, this line:

Enter passphrase for key '/home/me/.ssh/id_rsa':

Full output:

me:~$ ssh [email protected] -v
OpenSSH_8.0p1 Debian-7, OpenSSL 1.1.1c  28 May 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to myhost.mydomain.com [2402:6540:110::1006] port 22.
debug1: Connection established.
debug1: identity file /home/me/.ssh/id_rsa type 0
debug1: identity file /home/me/.ssh/id_rsa-cert type -1
debug1: identity file /home/me/.ssh/id_dsa type -1
debug1: identity file /home/me/.ssh/id_dsa-cert type -1
debug1: identity file /home/me/.ssh/id_ecdsa type -1
debug1: identity file /home/me/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/me/.ssh/id_ed25519 type -1
debug1: identity file /home/me/.ssh/id_ed25519-cert type -1
debug1: identity file /home/me/.ssh/id_xmss type -1
debug1: identity file /home/me/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.0p1 Debian-7
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Debian-10
debug1: match: OpenSSH_7.9p1 Debian-10 pat OpenSSH* compat 0x04000000
debug1: Authenticating to myhost.mydomain.com:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:jxxxYGexxx0GYxhBEUQ4vExxxP+WlhrxxxgdkHhtLk
debug1: Host 'myhost.mydomain.com' is known and matches the ECDSA host key.
debug1: Found key in /home/me/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/me/.ssh/id_rsa RSA SHA256:gUpmLxxx/q7dvl/C8mExxx0jCGz6xxxwUpxxxiTPk
debug1: Will attempt key: /home/me/.ssh/id_dsa
debug1: Will attempt key: /home/me/.ssh/id_ecdsa
debug1: Will attempt key: /home/me/.ssh/id_ed25519
debug1: Will attempt key: /home/me/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/me/.ssh/id_rsa RSA SHA256:gUpxxxH5J/q7xxx/C8mxxxk0jCGzxxx/xxxgxxxiTPk
debug1: Server accepts key: /home/me/.ssh/id_rsa RSA SHA256:gUpxxxH5J/q7xxx/C8mE9qk0xxxz6sX/xxxxxx0iTPk
Enter passphrase for key '/home/me/.ssh/id_rsa':
debug1: Authentication succeeded (publickey).
Authenticated to myhost.mydomain.com ([2xxx:6xxx:110::1xxx]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Remote: /root/.ssh/authorized_keys:19: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /root/.ssh/authorized_keys:19: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
setsockopt IPV6_TCLASS 16: Operation not permitted:
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Linux myhost.mydomain.com 4.19.0-kali4-amd64 #1 SMP Debian 4.19.28-2kali1 (2019-03-18) x86_64

The programs included with the Kali GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Oct 21 18:15:59 2019 from 2xxx:6xxx:exxx:70::1xxx

Actual output

Output on windows showing it failing to load the id_rsa key due to an invalid format, but one that works on linux/WSL.

Load key "C:\\Users\\me/.ssh/id_rsa": invalid format

Full Output:

PS C:\Users\me\.ssh> & 'C:\Program Files\OpenSSH-Win64\ssh.exe' [email protected] -v
OpenSSH_for_Windows_8.0p1, LibreSSL 2.6.5
debug1: Connecting to myhost.mydomain.com [2402:6540:110::1006] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\me/.ssh/id_rsa type 0
debug1: identity file C:\\Users\\me/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\me/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\me/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\me/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\me/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\me/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\me/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\me/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\me/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Debian-10
debug1: match: OpenSSH_7.9p1 Debian-10 pat OpenSSH* compat 0x04000000
debug1: Authenticating to myhost.mydomain.com:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:jxxxGeJexxxxhBEUQ4xxxZP+WlhrxxxHhtxxx
debug1: Host 'myhost.mydomain.com' is known and matches the ECDSA host key.
debug1: Found key in C:\\Users\\me/.ssh/known_hosts:3
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: C:\\Users\\me/.ssh/id_rsa RSA SHA256:gxxxLcH5xxxdvl/C8mxxxk0jCxxxwUpgSi0xxx
debug1: Will attempt key: C:\\Users\\me/.ssh/id_dsa
debug1: Will attempt key: C:\\Users\\me/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\me/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\me/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: C:\\Users\\me/.ssh/id_rsa RSA SHA256:gxxxLcHxxxq7dxxx8mE9qkxxx6sX/wxxxi0iTPk
debug1: Server accepts key: C:\\Users\\me/.ssh/id_rsa RSA SHA256:gUpmLcxxxq7dvl/C8xxxqk0xxxz6sX/wUxxxi0iTPk
Load key "C:\\Users\\me/.ssh/id_rsa": invalid format
debug1: Trying private key: C:\\Users\\me/.ssh/id_dsa
debug1: Trying private key: C:\\Users\\me/.ssh/id_ecdsa
debug1: Trying private key: C:\\Users\\me/.ssh/id_ed25519
debug1: Trying private key: C:\\Users\\me/.ssh/id_xmss
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
@CMCDragonkai
Copy link

I'm getting this on my RSA key that is password protected.

I have an AES-128-CBC rsa key that is password protected. I'm beginning to think the Windows ssh including Win32-OpenSSH just doesn't support this kind of key.

@troyfontaine
Copy link

troyfontaine commented Jan 27, 2020

Digging into this, if you password protect a key using Libressl on Windows the delimiter for the private key is drastically different from that used to protect a key using OpenSSL on Linux.

Windows is using OpenSSH 8.0 and the one I installed via Chocolatey was built with Libressl. Attempting to read in the key to Libressl results in the error 1204969060:error:02FFF002:system library:func(4095):No such file or directory:bio/bss_file.c:255:fopen.

Installing OpenSSL via Chocolatey I get version 1.1.1d and the error 20372:error:02001003:system library:fopen:No such process:crypto\bio\bss_file.c:69:fopen

Well, this is fun, I can open the file using openssl/libressl as long as I specify the path in Windows format exclusively. So that's a dead end. It looks like it is specifically an issue with ssh/ssh-add.

Meanwhile, Ubuntu WSL is using OpenSSH 7.6p1 built with OpenSSL 1.0.2n.

EDIT: Okay, looks like it comes down to a change that occurred in OpenSSH 7.8-they changed the format of the private keys, so this is a problem from upstream?

@maertendMSFT
Copy link
Collaborator

Can you try this on the latest version? Please open a new issue if you see this again.

@DavidHenri008
Copy link

I am getting this issue as well with version OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2.

OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Reading configuration data C:\\Users\\dxh06/.ssh/config
debug1: C:\\Users\\dxh06/.ssh/config line 5: Applying options for dcaf
debug1: C:\\Users\\dxh06/.ssh/config line 11: Applying options for *
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolve_canonicalize: hostname 192.168.2.11 is address
debug2: ssh_connect_direct
debug1: Connecting to dcaf [192.168.2.11] port 8101.
debug1: Connection established.
load pubkey "C:\\Users\\dxh06/.ssh/id_rsa": invalid format
debug1: identity file C:\\Users\\dxh06/.ssh/id_rsa type -1
debug3: Failed to open file:C:/Users/dxh06/.ssh/id_rsa-cert error:2
debug1: identity file C:\\Users\\dxh06/.ssh/id_rsa-cert type 4
debug3: Failed to open file:C:/Users/dxh06/.ssh/id_dsa error:2
debug3: Failed to open file:C:/Users/dxh06/.ssh/id_dsa.pub error:2
debug1: identity file C:\\Users\\dxh06/.ssh/id_dsa type -1
debug3: Failed to open file:C:/Users/dxh06/.ssh/id_dsa-cert error:2
debug3: Failed to open file:C:/Users/dxh06/.ssh/id_dsa-cert.pub error:2
debug1: identity file C:\\Users\\dxh06/.ssh/id_dsa-cert type -1
debug3: Failed to open file:C:/Users/dxh06/.ssh/id_ecdsa error:2
debug3: Failed to open file:C:/Users/dxh06/.ssh/id_ecdsa.pub error:2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
@CMCDragonkai @troyfontaine @maertendMSFT @DavidHenri008 @Greenwolf and others