PEM_read_PrivateKey failed issue

Peter Stuge
Sun, 19 Nov 2006 06:07:31 -0000

On Sat, Nov 18, 2006 at 06:04:14PM +0100, Alain G. Fabry
wrote:
> When I try to change the password on the key it give me the
> 'PEM_read_PrivateKey failed' problem, this also prevents me from
> connecting to another host.

[..]

> 2. Changing the password
>
> afabry at ducati-748 21:20 % ssh-keygen -v -p -f .ssh/test.pub

-f takes the private key file as argument. Drop .pub


> debug1: PEM_read_PrivateKey failed
> debug1: read PEM private key done: type <unknown>
> Enter old passphrase:
> debug1: PEM_read_PrivateKey failed
> debug1: read PEM private key done: type <unknown>
> Bad passphrase.

The error message could be more informative I suppose.

ssh-keygen tries to do what you told it - read a private key from
test.pub, and it reads a key of type <unknown>.

It asks for the passphrase and tries to use the passphrase to decrypt
the private key read from the file, in order to get a key of a known
type.

Since decrypting with the passphrase produced a key of type <unknown>
ssh-keygen assumes that the incorrect passphrase was given.

Needless to say this does not work when the input is not a key of the
correct format. I don't think it is possible to recognize an
encrypted private key, hence ssh-keygen can't tell when it gets the
wrong input. (Or can it?)


//Peter