TL;DR
FWIW, I ran into this problem today.
I never figured out what the new install of Win32 "portable openssh" 8.0.p1 didn't like about the key files - I just created new keys and added them to github and gitlab:
ssh-keygen -o -t rsa -b 4096 -C "Nouveau format OpenSSH pour github" -f C:\Users\mburr\.ssh\github.mburr-precor.key-2.id_rsa
Détails
I had a working install of OpenSSH from the https://github.com/PowerShell/openssh-portable project (as installed by Chocolatey). But a few days ago I had to perform a "repair install" of Windows and therefore had to reinstall OpenSSH.
After that my keys used to authenticate to github and gitlab would no longer work giving the "invalid format" error. These were the identical key files that had been on the system before (the Repair Reinstall didn't remove those files).
I found no problems with line endings (all LF and an LF at the end of the file). The keys worked on a Linux system - and I later found that they worked with the OpenSSH included with Git for Windows v2.33.1.
using the Win32 "portable OpenSSH" (from https://github.com/PowerShell/openssh-portable as installed by Chocolatey)
# Private key file error: "invalid format"
#
C:\devtrees>"c:\Program Files\OpenSSH-Win64\ssh.exe" -V
OpenSSH_for_Windows_8.0p1, LibreSSL 2.6.5
C:\devtrees>"c:\Program Files\OpenSSH-Win64\ssh.exe" -F c:\util\emptyfile -i c:\users\mburr\.ssh\github.mburr.id_rsa -T git@github.com
Load key "c:\\users\\mburr\\.ssh\\github.mburr.id_rsa": invalid format
git@github.com: Permission denied (publickey).
#-------------------------------------------------------
# using the OpenSSH that comes with Git for Windows v2.33.1
# No problem with the private key
#
C:\devtrees>c:\git\usr\bin\ssh.exe -V
OpenSSH_8.8p1, OpenSSL 1.1.1l 24 Aug 2021
C:\devtrees>c:\git\usr\bin\ssh.exe -F c:\util\emptyfile -i c:\users\mburr\.ssh\github.mburr.id_rsa -T git@github.com
Enter passphrase for key 'c:\users\mburr\.ssh\github.mburr.id_rsa':
Hi mburr! You've successfully authenticated, but GitHub does not provide shell access.
(emptyfile
is just that. I specified it as the config file with -F to force ssh to ignore ~/.ssh/config
)
I never figured out what the Win32 "portable openssh" 8.0.p1 didn't like about the key files - I just created new keys and added them to github and gitlab:
ssh-keygen -o -t rsa -b 4096 -C "Nouveau format OpenSSH for github" -f C:\Users\mburr\.ssh\github.mburr-precor.key-2.id_rsa
Problème résolu.
0 votes
Juste remarqué quelque chose : il devrait être chmoded 0400 (lecture seule). Il semble que ce ne soit pas le cas ici, car l'utilisateur a le privilège d'écriture.
0 votes
J'avais juste besoin d'une nouvelle ligne à la fin de la clé privée. Copié d'Ubuntu sur Mac et rencontré une erreur.