Secure Shell (SSH) keys are a cornerstone of modern web development. If you’re deploying code, managing servers, or working with version control systems like Git, you’ll often need an SSH key pair. In this article, we’ll explain what an SSH key pair is, why it matters, and how to generate one on common platforms: Linux, Windows (with PuTTY), and macOS/iOS. We’ll also cover how to format the key correctly for use on a Linux server.
What is an SSH Key Pair?
An SSH key pair is a set of two cryptographic files used for secure communication between your computer and a remote server:
- Private Key: This stays on your local machine. Think of it like your password—never share it.
- Public Key: This can be shared freely. You place this on the server you want to connect to.
When you connect via SSH, the server checks that your private key matches the public key it has on file. This allows you to log in securely without typing a password.
Generating an SSH Key on Linux
Most Linux distributions include the ssh-keygen tool. You can create a new key pair with the default filename, or specify a custom name if you need multiple keys.
Quick start (default filename)
- Open a terminal.
- Run:
12ssh-keygen -t ed25519 -C "your_email@example.com"-t ed25519specifies the algorithm. Ed25519 is modern and recommended, but you can usersafor compatibility.-Cadds a comment, usually your email.
- Press Enter to accept the default location (
~/.ssh/id_ed25519). - Optionally enter a passphrase for extra security.
This generates:
~/.ssh/id_ed25519→ Private key~/.ssh/id_ed25519.pub→ Public key
Specify a custom filename
Use the -f option to save the key with a custom name. This is helpful if you manage multiple servers or services.
|
1 2 |
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_ed25519_prod |
- The private key will be
~/.ssh/id_ed25519_prod - The public key will be
~/.ssh/id_ed25519_prod.pub
You can also set a passphrase at generation time:
|
1 2 |
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_ed25519_prod -N "your-passphrase" |
Use -N "" to create a key without a passphrase.
Using a custom key
To connect with a custom key:
|
1 2 |
ssh -i ~/.ssh/id_ed25519_prod username@your.server.com |
Or, make it easier by adding an entry to your SSH config (~/.ssh/config):
|
1 2 3 4 5 |
Host prod-server HostName your.server.com User username IdentityFile ~/.ssh/id_ed25519_prod |
Now you can connect with:
|
1 2 |
ssh prod-server |
Generating an SSH Key on Windows with PuTTY
Windows doesn’t come with ssh-keygen by default, but PuTTY provides a tool called PuTTYgen.
- Download PuTTY and install it.
- Open PuTTYgen.
- Under Parameters, choose Ed25519 (or RSA if needed).
- Click Generate and move your mouse around the blank area to create randomness.
- Once complete, save the two files:
- Private key (
id_ed25519.ppk) → keep safe on your computer. - Public key (copy from the box labeled “Public key for pasting into OpenSSH authorized_keys file”).
- Private key (
⚠️ Important: The text in the PuTTYgen box may look different than Linux’s .pub file. Copy the full key string and paste it into your server’s ~/.ssh/authorized_keys file as a single line.
Generating an SSH Key on macOS and iOS
On macOS
macOS comes with the same ssh-keygen tool as Linux. Use the same command:
|
1 2 |
ssh-keygen -t ed25519 -C "your_email@example.com" |
The keys will be stored in ~/.ssh/.
On iOS
If you’re working from an iPhone or iPad, you can use a terminal app like Termius or iSH:
- Install Termius from the App Store.
- Inside the app, go to Settings → Keychain → Generate Key.
- Choose Ed25519, give it a name, and save.
- Termius will let you copy the public key to use on your server.
Formatting Your Public Key for a Linux Server
To use your key, the public key must be placed in a specific file on your server:
- Connect to your server (using a password this one time).
- Open the file:
12nano ~/.ssh/authorized_keys
(Create the file and folder if it doesn’t exist:mkdir -p ~/.ssh && chmod 700 ~/.ssh) - Paste your public key on a single line. It should look like this:
12ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBV... user@example.com - Save and exit.
- Set correct permissions:
12chmod 600 ~/.ssh/authorized_keys
Now you can log in without a password.
Common Options and Tips
- Algorithm: Use
ed25519when possible. RSA is still supported but less efficient. - Passphrases: Add one for stronger security. You’ll need to enter it each time unless you use an SSH agent.
- Multiple Keys: You can create multiple keys for different servers or services by using the
-fflag. - Checking Keys: Your public key should always be a single line starting with
ssh-ed25519orssh-rsa.
Conclusion
SSH keys make connecting to servers more secure and more convenient. Whether you’re on Linux, Windows, or iOS, generating and installing an SSH key pair is straightforward once you understand the steps. As a web developer, learning this workflow will save you time and strengthen your security practices.




