An SSH key pair is easy to generate. The parts that deserve care are choosing a safe filename, keeping the private key private, and confirming the server accepts the matching public key.

The steps below use OpenSSH, available from PowerShell, macOS Terminal, and Linux shells. Run the commands on the computer you connect from.

Check before creating a key

Look in your .ssh directory first. An existing private key may already grant access to servers or Git accounts, so don't replace one casually.

On macOS or Linux:

ls -la ~/.ssh 

In PowerShell:

Get-ChildItem "$env:USERPROFILE\.ssh" -File -ErrorAction SilentlyContinue 

A typical pair is id_ed25519 and id_ed25519.pub. The file ending in .pub is the public key; the one without that suffix is the private key. If you see an overwrite prompt later, answer n unless you intentionally mean to replace that identity and have updated every service that trusts it.

Generate a key pair

For a modern OpenSSH setup, Ed25519 is a sensible default:

ssh-keygen -t ed25519 -C "laptop-key" 

The -C value is just a human-readable comment. It can be a device label or email address; it isn't a password or an authentication requirement.

You'll be prompted for a file path and a passphrase. Press Enter to use the default path if it isn't already occupied. Set a strong passphrase for normal personal use: it protects the private key if someone obtains the file. The passphrase is not your server password and isn't sent to the server. Nothing will appear on screen while you type it.

The default location is usually ~/.ssh/id_ed25519 on macOS and Linux, and C:\Users\YOUR_NAME\.ssh\id_ed25519 on Windows. OpenSSH also creates a matching .pub file. A success message, fingerprint, or randomart confirms key generation—not that a server has authorized the key.

If ssh-keygen isn't found, check that the OpenSSH client is installed or enabled for your system. On Windows, the OpenSSH Client is an optional feature; on Linux, install the appropriate OpenSSH client package.

Use a separate filename when needed

If a default key already exists, or you want a separate identity for work, specify a new path with -f:

ssh-keygen -t ed25519 -C "work-laptop" -f ~/.ssh/id_ed25519_work 

In PowerShell, use the Windows home directory explicitly:

ssh-keygen -t ed25519 -C "work-laptop" -f "$env:USERPROFILE\.ssh\id_ed25519_work" 

These commands create id_ed25519_work and id_ed25519_work.pub. Keep the private file on your machine. Only the .pub file is meant to be copied to a server or registered with a Git service.

Verify the public key, then install it

You can print the public key's fingerprint without exposing private-key material:

ssh-keygen -lf ~/.ssh/id_ed25519.pub 

For a custom filename, substitute its .pub path. The fingerprint identifies your key; it is different from the host-key fingerprint SSH may show when you first connect to a server.

To display the public key for copying on macOS or Linux:

cat ~/.ssh/id_ed25519.pub 

In PowerShell, copy it to the clipboard:

Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub" | Set-Clipboard 

Never copy or paste the file without .pub. A private key should not go into a website, chat, support ticket, or authorized_keys file.

For a Linux server, ssh-copy-id can install the public key if you already have a working login method:

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server 

If you need a walkthrough of that installation step, see this guide to copying an SSH public key with ssh-copy-id. If you don't have ssh-copy-id, add the public key to the correct account's ~/.ssh/authorized_keys using a method appropriate for your system.

Test authentication before changing server settings

Try a new connection using the key you just installed:

ssh -i ~/.ssh/id_ed25519 user@server 

For a custom key, replace the path with its private-key filename. A prompt for the key's passphrase is normal. If you see Permission denied (publickey), the key may not be authorized for that account, or SSH may be using a different username or key. Generation and server authorization are separate steps; creating another key usually won't fix an installation or account mismatch.

If the client reports WARNING: UNPROTECTED PRIVATE KEY FILE, check the private key's permissions. On Unix-like systems, chmod 600 is a common way to restrict access; this explanation of SSH key permissions covers what that setting means. Windows uses ACLs rather than Unix permission bits, so don't assume the same command applies there.

Once the new key works, keep the private file backed up securely if you need recovery, and avoid deleting an older key until you've confirmed nothing still depends on it. The essential rule is simple: distribute the public key, protect the private key, and test access before making other authentication changes.

I originally published a more detailed version of this guide on the ShadeTerm blog.

I'm also building ShadeTerm — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.