A2oz

How to Create a New SSH Key?

Published in Security 2 mins read

Creating a new SSH key is a straightforward process that involves using the ssh-keygen command in your terminal.

Generating an SSH Key

  1. Open your terminal.
  2. Run the command: ssh-keygen
  3. Choose a file location for your key: If you don't specify a location, the key will be saved in your home directory under .ssh.
  4. Enter a passphrase: This is optional, but highly recommended for security.
  5. Confirm your passphrase: Type it again.

Understanding Key Components

Once generated, you'll have two files:

  • id_rsa: This is your private key. Keep this file secure and private.
  • id_rsa.pub: This is your public key. You'll share this with servers or services that you want to access.

Adding Your Public Key to a Server

To use your new SSH key, you'll need to add your public key to the server you want to access.

Here's how:

  1. Copy your public key: Open the id_rsa.pub file and copy the contents.
  2. Add the public key to the server: There are different ways to do this, depending on the server you are using.
    • SSH: You can use the ssh-copy-id command to copy the key directly to the server.
    • Manual addition: You can add the public key to the authorized_keys file on the server.

Practical Insights

  • Use a strong passphrase: Choose a complex passphrase that you can remember easily.
  • Protect your private key: Never share your private key with anyone.
  • Use different key pairs for different servers: This helps to improve security.

Related Articles