How can I regain SSH access if I:

  • Have physical access to the device
  • Do not have a way of plugging in an external monitor (or serial console)
  • Was previously using SSH
  • I asked/answered this, because I didn't see my answer in any of the other questions, and I don't have enough reputation to post it on those.
    – Johntron
    Oct 8, 2023 at 20:46
  • How did you lose "SSH access"?
    – Milliways
    Oct 8, 2023 at 23:02
  • @Milliways I built a new PC and didn't save my old SSH key. Note: password-based authentication was disabled.
    – Johntron
    Jan 18 at 16:04

1 Answer 1



  1. If you don't already have an SSH private/public keypair, generate one
  2. Stick the SD card in the same machine as the SSH keypair
  3. Append the public key (.pub extension) to the .ssh/authorize_keys file in home directory of the user you're trying to connect with - see "Appending", "Key location", and "Permissions" below for details.
  4. Put SD card back in Pi and start it up
  5. Connect using ssh -i (path to private key) (user)@(address)

If you were using SSH previously, you should be presented with a remote terminal. This just worked for me - enjoy.


In Linux, you can use the following to append one file to another: cat source_file >> detination_file. For me, appending my SSH public key was as simple as: cat ~/.ssh/id_rsa.pub >> /media/rootfs/home/pi/authorized_keys; however, be sure to check the result - sometimes there's a line break missing, and you'll need to insert one manually.

Key location

If you've got the SD card mounted on some other machine, you need to know two things:

  1. Where the SD card is mounted
  2. For the user you're trying to login with, the location on the SD card of the home directory (often /home/pi)

With these two, the location is: (SD card)/(path to home folder). For me on Pop OS!, this is /media/rootfs/home/pi/authorized_keys


  • The .ssh directory on the SD card must have be rwx for user ONLY (700)
  • The authorized key must be rw for user ONLY

You can run these commands to set permissions correctly:

cd /media/rootfs/home/pi
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
  • You can't up-vote your own answer, but you can vote to accept it. This is a good thing because it lets others know this is the answer that worked for you.
    – Seamus
    Oct 13, 2023 at 17:45

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.