How to Create an SSH Key: A Complete Guide
SSH keys are one of the most reliable ways to secure remote connections — more robust than passwords and far less vulnerable to brute-force attacks. If you're managing servers, pushing code to GitHub, or accessing remote machines, understanding how to create and use SSH keys is a foundational skill.
What Is an SSH Key (and Why It Matters)?
SSH stands for Secure Shell. It's a protocol that lets you connect to remote computers over a network securely. An SSH key pair replaces the need for a password by using cryptographic verification instead.
The key pair consists of two parts:
- Private key — stays on your local machine, never shared
- Public key — copied to the remote server or service you want to access
When you attempt a connection, the server checks whether your private key mathematically matches the public key it has on file. No password travels over the network. No guessable string. Just cryptographic proof.
Choosing a Key Type Before You Start 🔑
Before running any command, you need to decide which algorithm to use. This affects security strength and compatibility.
| Key Type | Notes |
|---|---|
| Ed25519 | Modern, fast, highly secure — recommended for most users today |
| RSA (4096-bit) | Widely compatible, especially with older systems and services |
| ECDSA | Elliptic curve variant; less universally supported than Ed25519 |
| DSA | Outdated — avoid this unless forced by a legacy system |
For most people on modern systems connecting to modern services, Ed25519 is the practical default. If you're working with legacy servers or enterprise systems that haven't been updated recently, RSA at 4096 bits offers strong compatibility.
How to Generate an SSH Key on Linux or macOS
Both Linux and macOS come with OpenSSH pre-installed, so key generation happens entirely in the terminal.
Step 1 — Open your terminal
Step 2 — Run the key generation command
For Ed25519: