Properly Generate an SSH Key Pair in Your Terminal

Karthik S
2 min read4 days ago

--

Secure authentication is essential when working with remote servers, Git repositories, and cloud environments. One of the most widely used authentication methods is SSH keys. In this guide, I will walk you through the process of generating an SSH key pair using a simple terminal command.

Open Your Terminal

First, open your terminal on Linux, macOS, or Git Bash (Windows) to proceed with generating an SSH key pair.

Run the SSH Key Generation Command

Execute the following command in your terminal

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Explanation of Parameters

  • -t rsa: Specifies the type of key to create. The RSA algorithm is the most commonly used.
  • -b 4096: Defines the key size in bits. A 4096-bit key is highly secure.
  • -C "your_email@example.com": Adds a comment to the key, typically your email address, for easy identification.

Choose a Location to Save the Key

After running the command, you will be prompted with

Enter file in which to save the key (/home/youruser/.ssh/id_rsa):
  • Press Enter to save the key in the default location: ~/.ssh/id_rsa.
  • Alternatively, specify a custom path if you want to store the key elsewhere.

Set a Passphrase (Optional)

Next, you will see

Enter passphrase (empty for no passphrase):
  • If you want to secure your key with an extra layer of protection, enter a strong passphrase.
  • Press Enter if you do not want to set a passphrase (not recommended for production systems).

Understanding the SSH Key Pair

Once generated, the SSH key pair consists of two files

  • Private Key: ~/.ssh/id_rsa (Keep this file secure and do not share it).
  • Public Key: ~/.ssh/id_rsa.pub (This file can be shared with others or uploaded to remote servers).

Final Thoughts

Your SSH key pair is now ready to be used for secure authentication! You can add your public key to remote servers, Git services like GitHub, or cloud platforms to enable passwordless authentication.

Let me know in the comments if you have any questions!

--

--

Karthik S
Karthik S

Written by Karthik S

🚀 DevOps Engineer | Exploring cloud, automation, and infrastructure

No responses yet