Blog

How to generate a secure SSH key pair

  • git
  • tutorial
  • devjournal

I make a new SSH key for every new account or server, and this is the note I come back to each time.

Generate an SSH key pair

  • Open your favorite terminal
  • Run the ssh-keygen command
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

For a strong key, use the type flag -t rsa with the bits flag -b 4096. The comment flag -C "[email protected]" labels the key, so you can later tell who owns it.

  • Specify the key file name. The default is id_rsa
  • Enter a passphrase (optional, but a good idea)

ssh-keygen-sample

Warning: if you already have a default key at ~/.ssh/id_rsa, do not overwrite it. You would lose SSH access to every server and Git platform that uses it. Give the new key its own name instead, such as id_rsa_avengers.

Resources

Also on dev.to

Loading the terminal…