Skip to content

Instantly share code, notes, and snippets.

@fagnercarvalho
Last active May 8, 2024 22:58
Show Gist options
  • Save fagnercarvalho/f0d8516f11df88eae9e6ee1b2ffbe528 to your computer and use it in GitHub Desktop.
Save fagnercarvalho/f0d8516f11df88eae9e6ee1b2ffbe528 to your computer and use it in GitHub Desktop.
Import SSH key into Raspberry PI (or any Linux host really)
  • Generate the private/public keys pair
ssh-keygen -t ecdsa -b 521
  • Import public key into your server
cat ~/.ssh/id_ecdsa_rpi.pub | ssh [email protected] "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
  • Make sure the permissions for the private key are correct

  • Login into the server using the key (with verbose enabled)

ssh -i C:\Users\Fagner\.ssh\id_ecdsa_rpi [email protected] -v
  • For future connections you can edit your .ssh/config file to link your private key to your server
Host raspberrypi.lan
  HostName raspberrypi.lan
  User pi
  IdentityFile ~/.ssh/id_ecdsa_rpi
  • Then you can connect without the -i parameter
ssh [email protected]
  • If you configured a passphrase to the private key and you don't want to be prompted every time you connect to the server use AddKeysToAgent
Host raspberrypi.lan
  HostName raspberrypi.lan
  User pi
  IdentityFile ~/.ssh/id_ecdsa_rpi
  AddKeysToAgent yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment