PEM_read_PrivateKey failed SSH error

I just spent 20 minutes trying to figure out why my passwordless SSH wasn’t working. I’ve done it dozens of times, but this time it wasn’t working and none of the Google results had a solution that helped.

It turns out I was pointing to the public key instead of the private key.

Short summary: Don’t point to the .pub keyfile with IdentityFile in .ssh/config.

A lot of the solutions I found were related to invalid keyfiles, but I’d generated the key with ssh-keygen on that machine, so I was fairly confident the keys were valid.

If you’re having the same problem, use

ssh -vvv

to get more debugging info.

If this saves someone else 20 minutes, my wasted time will not have been in vain.





  1. Thanks man. I was beating my head on this as well; also had IdentityFile pointing at the .pub.

      » Comment by Brian Dunn on February 17, 2011 @ 9:08 am
  2. I’m glad this helped.

      » Comment by Dan on February 17, 2011 @ 9:18 am
  3. I am running Centos 5.5. Had the issue above. As long as I specified a passphrase with ssh-keygen, publickey never worked. If I use a blank passphrase, it works first time, every time.

      » Comment by Bill Cunningham on April 4, 2011 @ 11:06 am
  4. @Bill Cunningham Thanks for the additional data point.

      » Comment by Dan on April 4, 2011 @ 11:56 am
  5. Found this after running ssh with the ‘-v’ option, and scroogling for ‘PEM_read_PrivateKey failed.’ Appreciate the information, I can’t believe I made such a rookie mistake!

    Thanks for the help.

      » Comment by Mike Davis on April 7, 2011 @ 3:32 am
  6. @Mike I felt the same way :)

      » Comment by Dan on April 7, 2011 @ 9:11 am
  7. My problem was completely different, but the ‘ssh -vvv’ tip helped me find it. I was using ‘ssh -v’ and that wasn’t enough verbosity to reveal the problem, but I saw it when running ‘ssh -vvv’. Thanks for the tip!

      » Comment by Anon on April 12, 2011 @ 11:04 am
  8. @Anon No problem.

      » Comment by Dan on April 12, 2011 @ 12:19 pm
  9. Thank You!

      » Comment by Javix on July 13, 2011 @ 3:20 pm
  10. @Javix No problem.

      » Comment by Dan on July 13, 2011 @ 3:22 pm
  11. Chalk up another “Thank you.” D’oh!

      » Comment by Todd on August 30, 2011 @ 12:02 pm
  12. I’ll toss another “Thank you” in basket. Cheers!

      » Comment by Ed on October 3, 2011 @ 12:34 pm
  13. Thank you!

    *Why can’t I remember this?*

      » Comment by William Notowidagdo on November 24, 2011 @ 11:51 pm


Post a comment










Number of readers
- home
comics
news links
other links

about me
blog archives
docs
entertainment
experiences
funny lists
humor
intellectual
interests
metafilter
music
opinions
photos
web designs
tools
software
webmaster help

Sign up
Enter your email address to be notified of new posts



Search blog archives

Calendar
January 2010
S M T W T F S
« Dec   Feb »
 12
3456789
10111213141516
17181920212223
24252627282930
31  







Random quote
(View all quotes)
"Don't worry about spilling some paint while working on the big picture."










(?) Choose theme:  X X X X X X