Course contentsShow
← Security
Lesson 1442 of 3,05229. Operating System Security - HardeningFree lesson

SSH Key Generation and Management

Generate secure SSH key pairs with appropriate algorithms (Ed25519, RSA 4096), set proper permissions, and manage key lifecycle.

SSH Key Generation and Management

You'll learn how to create, configure, and maintain SSH key pairs with strong cryptographic algorithms and proper security controls.

What Are SSH Keys?

SSH keys are cryptographic credentials that provide a more secure alternative to password authentication. Think of them like a physical key and lock: your private key stays with you (never shared), while the public key can be freely distributed to servers you want to access. Unlike passwords, keys are nearly impossible to brute-force when properly configured.

Generating Secure Keys

Modern SSH keys should use Ed25519 (preferred for its security and performance) or RSA 4096-bit (for legacy compatibility):

# Ed25519 - Modern, secure, fast (recommended)
ssh-keygen -t ed25519 -C "your_email@example.com"

# RSA 4096-bit - Compatible with older systems
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

The -C flag adds a comment (usually your email) to help identify the key's purpose.

Critical Permission Settings

Private keys must be protected with restrictive permissions. World-readable private keys are a critical security flaw:

# Private key - only owner can read
chmod 600 ~/.ssh/id_ed25519

# Public key - owner can read/write
chmod 644 ~/.ssh/id_ed25519.pub

# SSH directory itself
chmod 700 ~/.ssh

Key Lifecycle Management

  • Generate unique keys per device/purpose (work laptop, personal machine, automation)
  • Protect with strong passphrases for added security
  • Rotate periodically (annually for user keys, more frequently for automated systems)
  • Revoke immediately when devices are lost or compromised
  • Audit authorized_keys files regularly to remove stale entries

Key Takeaway: Use Ed25519 or RSA 4096 for SSH keys, always set 600 permissions on private keys, and manage keys as you would any other critical credential through their entire lifecycle.