Error message
Load key "/path/to/key": invalid format
The path is filled in per invocation. The wording depends on the crypto library OpenSSH was built with: with OpenSSL 1.1 or LibreSSL (macOS) every failure below prints "invalid format"; builds with OpenSSL 3 (Ubuntu 22.04 and later, Debian 12 and later) print "error in libcrypto" for most of them and keep "invalid format" for damaged PEM-format keys. A changed character inside the body gives "unknown or unsupported key type" on all of them.
OpenSSH — ssh, ssh-keygen, ssh-add
What it means
OpenSSH tried to load a private key file and could not parse it in any format it knows (OPENSSH PRIVATE KEY, PKCS#8, legacy PEM). The file is damaged, truncated, in a foreign format like PuTTY's .ppk, or is not a private key at all — this is a file-format failure, before any passphrase or server interaction.
Why it happens
Copy-paste damaged the key
commonKeys moved through chat, email or terminals lose trailing newlines, gain wrapped lines or smart characters, or drop the final dashes. The base64 body of an OPENSSH PRIVATE KEY block is length-sensitive; one lost character invalidates the file. (A missing final newline alone is a classic trigger.)
PuTTY .ppk file used with OpenSSH
commonPuTTY's key format ("PuTTY-User-Key-File-2: ...") is not OpenSSH's. Pointing ssh -i at a .ppk fails exactly here; the key must be converted once.
Public key where the private key belongs
commonssh -i id_ecdsa.pub (the .pub file), or an authorized_keys line saved as the identity file — the private-key loader finds public-key content and reports invalid format.
Truncated or partially synced file
occasionalA cloud-synced or scp-interrupted key file cut mid-body parses as garbage. Reproduced: truncating a valid key file yields exactly "invalid format" on OpenSSH 8.4 and on macOS.
How to fix it
- 1.
Inspect the framing first
The first and last lines plus a validity probe (-y prints the public key if — and only if — the private key parses) identify the failure class in seconds.
bash head -1 ~/.ssh/id_ecdsa # -----BEGIN OPENSSH PRIVATE KEY----- tail -c 50 ~/.ssh/id_ecdsa | xxd | tail -1 # must end with 0a (newline) ssh-keygen -y -f ~/.ssh/id_ecdsa # parses? prints the public key - 2.
Convert PuTTY keys to OpenSSH format
One-time conversion with puttygen; afterwards the key works with ssh, ssh-add and ssh-agent.
bash puttygen key.ppk -O private-openssh -o ~/.ssh/id_converted chmod 600 ~/.ssh/id_converted - 3.
Transfer keys losslessly
Move key files with scp/rsync rather than clipboards, keep permissions at 600, and if the private key is unrecoverable, generate a fresh pair — modern OpenSSH favors Ed25519.
bash scp -p old-host:~/.ssh/id_ecdsa ~/.ssh/ # or start clean: ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519