I use Raspberry Pi Imager to create an SD card with Raspberry Pi OS Lite (64-Bit) for my Raspberry Pi 3B. I activate SSH and choose authentication via public key. Until recently this worked fine but now I can't access my Raspberry Pi anymore after setting it up.

I removed all keys but id_rsa and id_rsa.pub from ~/.ssh and flashed a new card. When trying to connect, this is what I got:

$ ssh [email protected]
The authenticity of host 'raspberrypi.local (2a01:c23:79cb:600:3e35:ed6b:e928:c9fc)' can't be established.
ED25519 key fingerprint is SHA256:Rmv+CEpgAS6meAB/9iR2rPX+Yu+VQNUGAXMbLWyQRZo.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'raspberrypi.local' (ED25519) to the list of known hosts.
[email protected]: Permission denied (publickey).

I'm especially irritated by the ED25519 reference. I created simple RSA keys with ssh-keygen (the ones you get if you just repeatedly hit enter).

I depend on regularly reflashing my SD cards without having to manually set up SSH all the time. How can I get SSH access working out of the box again when flashing with Raspberry Pi Imager?

  • Make sure your ~/.ssh/known_hosts file has permissions -rw------- or authentication will fail due to permissions. From what you describe, it sounds like a permissions problem somewhere. Additionally, the Public-Key from the host you are trying to connect FROM must be in your authorized_keys file. Commented Sep 24, 2022 at 6:35

2 Answers 2


You haven't specified WHAT platform you are using but most cache know hosts.

This is NOT a Pi problem but a problem with your computer/s. Alternately you can configure your system to ignore host changes.

You NEED to remove this from your host/s this may depend on on platform but is often a known_hosts file.

Continually reflashing with new image is a poor strategy as new host keys are generated each time. This confuses any security system as the MAC remains the same. If you want to do this you need to remove all cached hosts.

It is also totally unnecessary to install new images - if you regularly upgrade there is no need. (I only install a new image every 2 years when a new version of Raspberry Pi OS is released.)

PS if you use multiple SD Cards in the same Pi you will experience the same issue.

  • I am trying to connect from macOS 12.6. I backed up ~/.ssh and started with new keys and a clean SSH directory without a known_hosts file. The problem persists.
    – 303
    Commented Oct 26, 2022 at 15:37

It turns out that I misinterpreted the public key input field of the Raspberry Pi Imager. It only showed the comment section of the key ("name@computer"), which led me to believe that it was pointing to a public key in ~/.ssh with that string.

In fact, the input field contained a full ED25519 key, which I must have copied over at some point, and of which I only saw the last part. Creating new keys over and over again didn't solve my problem because the public key in the input field was being used the entire time.

Copying the public key I wanted to use into that input field solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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