linux

Generating SSH Keys for Your Machine

Quick guide to generating SSH public and private key pairs using ssh-keygen on Linux. Understand id_rsa and id_rsa.pub files.

To generate a private and public SSH key pair, run ssh-keygen.

  • Running ssh-keygen shows this prompt:
terminal
Generating public/private rsa key pair.Enter file in which to save the key (/home/username/.ssh/id_rsa):
  • By default, the keys save to the .ssh/ folder.

Things to note:

  • id_rsa contains the private key.
  • id_rsa.pub contains the public key.
  • known_hosts stores the host keys of the servers you’ve connected to over SSH.

ssh-keygen -t rsa -C "your_email@example.com" generates an SSH key pair and associates it with your email.