StarDomain

Generating SSH Keys

Generating SSH Keys

SSH keys provide a secure, password-free method of authenticating to your server. They use public-key cryptography — you keep a private key on your local machine and place the corresponding public key on the server. This guide covers generating SSH keys on all major platforms.

Why Use SSH Keys?

  1. Stronger security: SSH keys are virtually impossible to brute-force, unlike passwords
  2. Convenience: No need to type passwords for every connection
  3. Automation friendly: Scripts and applications can connect without storing passwords
  4. Auditable: Each key pair is unique, making it easy to track who accessed the server

Generating Keys on Linux and macOS

Linux and macOS include the ssh-keygen utility by default.

Step 1: Open Terminal

Open your terminal application (Terminal on macOS, or any terminal emulator on Linux).

Step 2: Generate the Key Pair

ssh-keygen -t ed25519 -C "[email protected]"

If your system does not support Ed25519, use RSA:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Step 3: Choose a File Location

When prompted, press Enter to accept the default location (~/.ssh/id_ed25519) or specify a custom path.

Enter a strong passphrase when prompted. This adds an extra layer of security — even if someone obtains your private key file, they cannot use it without the passphrase.

Tip: Use ssh-agent to cache your passphrase so you do not have to type it for every connection. Run eval "$(ssh-agent -s)" followed by ssh-add ~/.ssh/id_ed25519.

Step 5: Verify the Keys

Two files are created:

  • ~/.ssh/id_ed25519 — your private key (keep this secret)
  • ~/.ssh/id_ed25519.pub — your public key (safe to share)

View your public key:

cat ~/.ssh/id_ed25519.pub

Generating Keys on Windows

Option A: Windows 10/11 Built-in SSH

Windows 10 and later include OpenSSH. Open PowerShell or Command Prompt:

ssh-keygen -t ed25519 -C "[email protected]"

The process is identical to Linux/macOS. Keys are saved to C:\\Users\\YourName\\.ssh\\.

Option B: PuTTYgen

If you use PuTTY as your SSH client:

  1. Download and install PuTTY from the official website
  2. Open PuTTYgen (included with PuTTY)
  3. Select EdDSA (Ed25519) or RSA (4096 bits) as the key type
  4. Click Generate
  5. Move your mouse randomly over the blank area to generate randomness
  6. Once generated, enter a passphrase in the Key passphrase field
  7. Click Save private key to save the .ppk file
  8. Copy the text from the "Public key for pasting" box — this is your public key

Tip: PuTTY uses .ppk format for private keys. If you need OpenSSH format, use PuTTYgen's Conversions > Export OpenSSH key menu option.

Adding Your Public Key to the Server

Once you have generated your key pair, copy the public key to your server:

From Linux/macOS

ssh-copy-id username@your-server-ip

This automatically appends your public key to the server's ~/.ssh/authorized_keys file.

Manual Method (Any Platform)

  1. Copy your public key content
  2. SSH into your server with your password
  3. Create the .ssh directory if it does not exist:

```

mkdir -p ~/.ssh

chmod 700 ~/.ssh

```

  1. Append the public key:

```

echo "your-public-key-content" >> ~/.ssh/authorized_keys

chmod 600 ~/.ssh/authorized_keys

```

Key Types Comparison

Key TypeSecuritySpeedCompatibility
Ed25519ExcellentFastModern systems
RSA 4096Very GoodSlowerUniversal
ECDSAGoodFastMost systems

Security Best Practices

  1. Always set a passphrase on your private key
  2. Never share your private key — only the public key goes on servers
  3. Use separate keys for different purposes (work, personal, automation)
  4. Set correct permissions: Private key should be chmod 600, .ssh directory should be chmod 700
  5. Rotate keys periodically — generate new keys annually and remove old ones

Troubleshooting

Permission Denied After Adding Key

  • Verify file permissions: chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
  • Ensure the public key is on its own line in authorized_keys
  • Check that the server's sshd_config allows key authentication: PubkeyAuthentication yes

ssh-keygen Command Not Found

  • Windows: Enable OpenSSH via Settings > Apps > Optional Features > Add OpenSSH Client
  • Linux: Install with sudo apt install openssh-client or sudo yum install openssh-clients

Need help with SSH key setup? Contact our support team at {{SUPPORT_EMAIL}} or open a ticket at {{SUPPORT_URL}}.