Black Friday Sale is live: save up to 85% on Web & WordPress HostingView Deals
Step-by-Step TutorialServer Operations & SecurityBeginner

How to Generate an SSH Key Pair: Step-by-Step Guide for Windows, macOS & Linux

Overview

Secure Shell (SSH) is the standard cryptographic network protocol used to log in to and manage remote servers. While SSH allows logging in with a standard username and password, password authentication is vulnerable to automated dictionary and brute-force attacks across the internet.

SSH key pairs provide far stronger authentication based on asymmetric public-key cryptography:

  • Private Key: Stored exclusively on your local computer. It is protected by filesystem permissions and, ideally, an encryption passphrase.
  • Public Key: Copied to the remote server’s ~/.ssh/authorized_keys file.

During the SSH handshake, the server issues a cryptographic challenge that can only be solved with the corresponding private key. The private key itself is never transmitted across the network.

In this tutorial, you will learn how to generate a modern SSH key pair on Windows, macOS, or Linux, choose the right algorithm, configure a passphrase, and manage your keys securely.

[!CAUTION] Strict Private Key Confidentiality: Your private key is equivalent to a master password. Never share your private key, never email it, never paste it into web chat or support tickets, and never commit it to Git repositories. Only the public key (ending in .pub) is ever shared with servers or hosting providers.


Operating System Prerequisites

The standard OpenSSH client tool ssh-keygen is available on all modern operating systems:

  • Windows 10 / 11: OpenSSH Client is pre-installed by default. Open Windows PowerShell or Windows Terminal. If not installed, enable it via Settings > Apps > Optional features > OpenSSH Client.
  • macOS: OpenSSH is built into macOS. Open Terminal (/Applications/Utilities/Terminal.app).
  • Linux: OpenSSH is standard on virtually all Linux distributions. Open your preferred terminal emulator.

Step 1: Generate the SSH Key Pair

Open your terminal or PowerShell and run the ssh-keygen command.

Ed25519 is the modern, highly secure elliptic curve algorithm recommended by OpenSSH:

ssh-keygen -t ed25519 -C "my-workstation-key"

Note: Replace "my-workstation-key" with a descriptive label (such as your computer name or environment) to easily identify the key later.

Alternative Algorithm: RSA (4096-bit)

If you need to connect to an older legacy server that does not support Ed25519:

ssh-keygen -t rsa -b 4096 -C "my-workstation-key"

Step 2: Choose File Location and Key Name

After running the command, ssh-keygen prompts you to specify a file location:

Generating public/private ed25519 key pair.
Enter file in which to save the key (~/.ssh/id_ed25519):
  • To accept the standard default location, press Enter.
  • On Linux and macOS, the default directory is ~/.ssh/.
  • On Windows, the default directory is under %USERPROFILE%\.ssh.

If you already have a key pair with that name and wish to keep it, specify a unique name (such as ~/.ssh/id_ed25519_server1).


Step 3: Set a Secure Passphrase

Next, the utility prompts you to enter a passphrase:

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

[!TIP] Always Use a Passphrase: A passphrase encrypts your private key file on your local disk using symmetric AES encryption. If your laptop is ever stolen or compromised, the thief cannot use your private key without knowing your passphrase. Choose a memorable phrase with letters, numbers, and spaces.

While typing, no characters will appear on screen. This is normal security behavior. Type your passphrase and press Enter, then re-type it to confirm.


Step 4: Inspect the Generated Key Files

Once complete, ssh-keygen displays your key fingerprint and a randomart visual image.

Navigate to your .ssh directory and view the files:

On Linux or macOS:

ls -la ~/.ssh/

On Windows PowerShell:

Get-ChildItem $env:USERPROFILE\.ssh

You will see two complementary files:

  1. id_ed25519 (Private Key): Your secret identity. Its permissions should be restricted to only your user account (chmod 600 ~/.ssh/id_ed25519 on Unix).
  2. id_ed25519.pub (Public Key): The public half. This is the text you upload to servers or paste into cloud provider dashboards.

Step 5: How to View and Copy Your Public Key

To authorize your key on a remote server or hosting control panel, you must copy the contents of the public key file (.pub):

On Linux or macOS:

cat ~/.ssh/id_ed25519.pub

On Windows PowerShell:

Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub

The output will look similar to this format:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExamplePublicKeyStringFormat my-workstation-key

Select and copy this single line. It is now ready to be deployed to your server.


Next Steps

Now that you have generated your cryptographic key pair, proceed to our tutorial on how to connect to a server with SSH to learn how to install your public key on a remote server and establish an authenticated terminal session.

Frequently Asked Questions

What is the difference between my public key and my private key?

Your public key (ending in .pub) is designed to be shared and placed on remote servers you wish to access. Your private key (without .pub) is your secret credential that must stay strictly on your local machine. Anyone who obtains your private key can authenticate as you on any server that trusts your public key.

Should I choose Ed25519 or RSA for my SSH key?

Ed25519 is the modern standard recommended for new keys. It uses elliptic-curve cryptography to provide faster signing and higher security with a compact key length. RSA with 4096-bit length remains widely supported for legacy systems that do not support Ed25519.

Can I add a passphrase to an existing SSH key later?

Yes. You can add or change the passphrase on an existing key at any time using the command 'ssh-keygen -p -f ~/.ssh/id_ed25519'.

Need Technical Assistance?

Web Hosting Wale support is available 24/7. Tickets are typically answered within 10-15 minutes.

Open Support TicketView All Support Channels