Skip to main content

SSH Authentication Methods

Chapter 11: Generating SSH Key Pairs with ssh-keygen

In Chapter 11, you will learn how to generate your first SSH key pair using the ssh-keygen command, understand where SSH stores your keys, set a passphrase to protect your private key, and verify your key pair is ready to use.

In the previous chapter, you learned about the different SSH key types and why Ed25519 is the recommended choice for all new keys. You now have everything you need to generate your first SSH key pair.

In this chapter, you will use the ssh-keygen command to generate your key pair, understand every option available to you, learn where SSH stores your keys, and set up a passphrase to protect your private key.

What Is ssh-keygen

ssh-keygen is the command-line tool that comes with OpenSSH specifically for generating, managing, and converting SSH key pairs.

It is available on Linux, macOS, and Windows (with the built-in OpenSSH client) and works the same way on all three platforms.

When you run ssh-keygen, it does three things:

  • Generates a mathematically linked public and private key pair.
  • Saves the private key to your local machine.
  • Saves the public key to your local machine with a .pub extension.

The private key stays on your machine forever. The public key is what you will copy to any server you want to access.

Learn Linux Fast: 7-Day Crash Course for Beginners
A complete 7-day crash course to help beginners master Linux, the command line, software management, and more. No experience needed!

The ~/.ssh Directory

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’