# How do you generate an SSH key?

Verified: 2026-11-20
Canonical: https://answerkb.com/how-to/tech/how-do-you-generate-an-ssh-key/

To generate an SSH key, run ssh-keygen (typically ssh-keygen -t ed25519 -C "your_comment") and save the key pair in your .ssh directory.

## Explanation

ssh-keygen creates a private key and a matching public key. The private key stays on your machine and should never be shared or committed to a repository. The public key (the file ending in .pub) can be added to a server's authorized_keys file or to a service such as GitHub. Ed25519 is a modern default when both sides support it; if you need older compatibility, some systems still use -t rsa -b 4096. An optional passphrase encrypts the private key at rest. After the key is generated, you can start ssh-agent and ssh-add the private key so you do not type the passphrase on every connection.

## Steps

1. **Open a terminal.** On Windows, use PowerShell or a terminal that provides OpenSSH.
2. **Run ssh-keygen.** A typical command is ssh-keygen -t ed25519 -C "your_comment". Accept the default path (~/.ssh/id_ed25519) or choose another, and optionally set a passphrase.
3. **Use the public key, protect the private key.** Copy the .pub file to the remote account or service. Do not share the private key file.

## Common queries

- How do I generate an SSH key?
- How to generate an SSH key?
- How can I generate an SSH key?
- How can you generate an SSH key?
- What's the way to generate an SSH key?
- What is the process to generate an SSH key?

## Related

### Easier
None.

### Harder
None.

### Siblings
None.

## Sources

- [OpenBSD manual page for ssh-keygen](https://man.openbsd.org/ssh-keygen)
