1

I changed the private key on my computer using ssh-keygen (I know... Why would anyone do this? A: I have no idea what I'm doing :#) and now every time I try to ssh into one of my raspberry pi's it tells me Permission denied (publickey).. I know there have been other posts on this with very good answers (a.k.a. The answer from mfa298 on this post https://www.raspberrypi.org/forums/viewtopic.php?p=1314932). The answers to previous posts seemed to either answer what went wrong (which is immensely useful) but not necessarily how to fix it once it is already screwed up or the suggestions did not work to fix my issue. Also, I tend to periodically use the same SD card on multiple pi's. I have tried removing the keys for the pi so that I can ssh into it using the password but am receiving the same issue. #improbablydoingitwrong

My Q: How do I make my computer and raspberry pi play nice again?

I know this has been addressed before but if someone could help me decipher what I need to do to make this go away, I would be very happy. I am doing all this headless but am able to console cable into the pi.

Project specifics: I am using a raspberry pi zero that I am trying to set up as a usb/ethernet gadget according to the adafruit tutorial (https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget). I am using the latest version of rasbian lite (or very close to it).

  • How did you change the key? Which key? What OS? What are you using to ssh into the Pi? – Milliways Nov 18 '19 at 21:36
  • @Milliways I'm using both an iMac and a MacbookPro both running Mojave, same issue on both. Using ssh coming from both and did not change the key on the iMac it's possible that is not the issue. I changed the key using ssh-keygen rsa. – Reid Nov 18 '19 at 21:56
  • I'm really fine just sshing into the pi and using the password but even that is not working for me. – Reid Nov 18 '19 at 21:57
  • Post the names of the files you have changed. – Dmitry Grigoryev Nov 19 '19 at 10:18
1

You receive the message below, trying to enter in your Raspberry with ssh:

Permission denied (publickey)

because in your Raspberry the configuration file

/etc/ssh/sshd_config

contains the option:

PasswordAuthentication no

and there is a mismatch between your new private key in the Mac (generated with ssh-keygen) and the corresponding old public key inside your Raspberry, normally listed in the file:

~/.ssh/authorized_keys

You have to replace the old public key with the new public key generated on the Mac.

If you simply want to reactivate the password authentication method on your Raspberry edit the file /etc/ssh/sshd_config to change the option:

PasswordAuthentication yes
  • 1
    You cannot set an option PasswordAuthentication yes in ~/.ssh/authorized_keys. That only contains public keys. You have to set this option in /etc/ssh/sshd_config. – Ingo Nov 19 '19 at 11:52
  • You are right, it was a copy and past error. Corrected, thank you – Roberto Giorgetti Nov 19 '19 at 11:54
0

macOS caches public keys keys in .ssh/known_hosts and normally warns if there is a conflict.

If this is your problem (and you haven't adequately explained what you did or what error you see) it can be fixed by deleting the offending key (or the whole file). There are many ssh settings on the Mac which determine how ssh connects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.