[KongchangAI]
· 2 min read· 1,429 words

SSH and PGP Key Upgrades: A Practical Guide to P-256, ED25519, and Curve25519

SSH and PGP Key Upgrades: A Practical Guide to P-256, ED25519, and Curve25519

A systematic guide to migrating SSH and PGP keys to elliptic curve algorithms, with practical steps and pitfalls.

Based on Seth Larson's article and Hacker News discussion, this piece covers upgrading SSH and PGP keys from RSA to P-256, ED25519, and Curve25519. It explains why ECC has become mainstream, then guides readers through discovering legacy keys, safely replacing SSH keys (add first, remove later), and handling PGP upgrades involving subkeys and trust network rebuilding. It highlights common pitfalls—permissions, ssh-agent caching, deployment keys—and offers tiered recommendations for individuals and teams, noting no consensus on rotation frequency.

SSH and PGP Key Upgrade Guide

Modern cryptography is migrating from traditional RSA to elliptic curve algorithms. Developer Seth Larson's article "How to find and upgrade SSH and PGP keys using P‑256, ED25519, and Curve25519" earned 333 upvotes and 117 comments on Hacker News, sparking widespread discussion about key upgrade practices. Rather than a simple list of commands, the article systematically addresses three core questions: how to find legacy keys, how to upgrade safely, and how to avoid common pitfalls.

Why Elliptic Curve Keys Have Become the Mainstream Choice

RSA dominated public key infrastructure for decades, but the performance overhead and storage costs of its key lengths have become increasingly apparent in the cloud-native era. Elliptic Curve Cryptography (ECC) achieves equal or even higher security strength with shorter keys. P-256 (NIST P-256, also known as secp256r1), ED25519, and Curve25519 are the three curves receiving the most attention today, each corresponding to different use cases and ecosystem preferences.

According to Seth Larson's analysis, ED25519 has become the de facto standard in SSH scenarios, with OpenSSH supporting it by default since relatively early versions. Migration in the PGP ecosystem is more complex, with GnuPG's support for Curve25519 having evolved across multiple versions. P-256, owing to its NIST standardization background, retains an irreplaceable position in enterprise environments with high compliance requirements.

Elliptic Curve Cryptography (ECC) security is based on the Elliptic Curve Discrete Logarithm Problem (ECDLP), unlike RSA's reliance on integer factorization. At equivalent security strength, ECC key lengths are far smaller than RSA: for example, a 256-bit ECC key roughly equals the security strength of a 3072-bit RSA key. This directly reduces computational overhead, bandwidth consumption, and storage requirements—particularly advantageous for resource-constrained mobile devices and cloud-native environments.

P-256 (secp256r1) is the NIST-standardized curve, whose parameters were generated using a verifiable random seed, though the transparency of the seed's origin is often questioned. ED25519 is based on the twisted Edwards form of Curve25519, designed with emphasis on side-channel resistance and deterministic signatures, with a fully transparent parameter selection process. Curve25519 itself is a Montgomery curve, primarily used for key exchange (e.g., X25519). All three fall under the ECC umbrella, but their design philosophies and ecosystem positioning differ.

How to Discover Legacy Keys in Use on Your System

The first step in upgrading isn't generating new keys—it's understanding the current state. Seth Larson recommends starting with the SSH directory, checking traditional key files like id_rsa and id_dsa under ~/.ssh, and using the ssh-keygen -l -f command to view each key's fingerprint and type. For PGP keys, use gpg --list-keys and gpg --list-secret-keys to list all public and private keys, paying attention to creation dates and algorithm identifiers.

One easily overlooked detail: a system may have multiple SSH configuration files (such as ~/.ssh/config and /etc/ssh/ssh_config) referencing different keys, all of which need to be checked one by one during upgrades. Developers in the Hacker News comments pointed out that deployment keys in CI/CD environments are often the most easily missed corner—these keys are typically mounted read-only and left unmaintained for long periods.

SSH Key Upgrades: A Practical Path from RSA to ED25519

The command to generate an ED25519 key is not complicated in itself: ssh-keygen -t ed25519 -C "comment". The real challenge lies in subsequent replacement and distribution. Seth Larson emphasizes several key steps: first append the new public key to the target server's authorized_keys file, verify that the new key can log in successfully, and then remove the old key. This "add first, remove later" order avoids the embarrassing situation of locking yourself out.

For scenarios requiring compatibility with legacy systems, P-256 is the safer choice, with the generation command ssh-keygen -t ecdsa -b 256. However, community attitudes toward P-256 are divided: some developers believe NIST curves' parameter provenance is insufficiently transparent and prefer ED25519, while others value P-256's broad support in Hardware Security Modules (HSMs) and smart cards. This divide was quite evident in the Hacker News discussion, with advocates on both sides.

Hardware Security Modules (HSMs) are physical devices dedicated to protecting and managing keys, providing tamper-resistant key storage and cryptographic operations. Many enterprise-grade HSMs and smart cards (such as YubiKey PIV) have native support for P-256, while support for ED25519 came later or is limited. This makes P-256 often the more practical choice in scenarios requiring hardware-level key protection. However, as devices like YubiKey gradually add Ed25519 support (e.g., via FIDO2 or OpenSSH's sk-ssh-ed25519 key type), this gap is narrowing.

The Complexity of PGP Key Upgrades

PGP key upgrades are far more complex than SSH. Generating a Curve25519 key in GnuPG requires using --quick-gen-key with future-default or explicitly specifying the cv25519 algorithm. Seth Larson notes that PGP keys are often bound to multiple subkeys (for signing, encryption, and authentication), which must be handled separately during upgrades, along with consideration of public key distribution on keyservers and generation of revocation certificates.

According to the article, one reason for the slow migration of the PGP ecosystem is that its trust model relies on long-accumulated signing relationships—changing the primary key means rebuilding the trust network. As a result, many developers choose to retain the old primary key for identity authentication and only upgrade the encryption subkey. This approach strikes a compromise between security and convenience but also increases the cognitive burden of key management.

The PGP Web of Trust is a decentralized trust model in which users establish trust paths by signing each other's public keys. Changing the primary key means all subkeys issued by the old primary key and third-party signing relationships need to be re-established, or the trust chain breaks. This is one of the core reasons for slow PGP migration. The practice of retaining the old primary key and only upgrading subkeys maintains identity continuity, but if the old primary key uses a weak algorithm (such as RSA 2048), it may still become an attack surface—a risk that must be weighed.

Common Pitfalls During the Upgrade Process

Drawing on Seth Larson's article and the Hacker News discussion, several high-frequency issues warrant vigilance. First, permissions: if a newly generated key file has overly broad permissions (such as 644), SSH will refuse to use it—the correct permission is 600. Second, in agent forwarding scenarios, the old key may still be cached by ssh-agent, requiring manual cleanup with ssh-add -D. Third, deployment keys on platforms like GitHub and GitLab need to be updated separately, as these platforms typically don't allow the same key to be reused across multiple repositories.

Another notable discussion point is the timing of key rotation. Some commenters suggest that rather than waiting for an algorithm to be broken before upgrading reactively, it's better to establish a regular rotation mechanism. But dissenting voices argue that frequent rotation increases operational risk, especially in teams where key distribution channels aren't sufficiently automated. There's currently no standard answer to this divide—it depends on the team's security maturity.

ssh-agent is OpenSSH's key management agent, used to cache private keys and handle signing requests. After key rotation, the agent may still hold old keys, causing new keys to not take effect or old keys to be used unexpectedly. ssh-add -D clears all cached keys, but a more granular approach is to use ssh-add -d <old_key_file> to remove them individually. Additionally, ssh-add -l lists the fingerprints of currently loaded keys for easy verification.

Practical Recommendations

For individual developers, prioritizing the upgrade of SSH keys to ED25519 is low-cost with clear benefits. For team environments, it's advisable to first inventory all locations where keys are used (including CI/CD, deployment scripts, and container images) and formulate a phased migration plan. PGP key upgrades should be approached more cautiously, with decisions made after assessing the cost of rebuilding the trust network. Seth Larson's original article provides complete command references and checklists, suitable as an operations manual during the migration process.

One-line Summary

A systematic overview of the practical paths and common pitfalls in migrating SSH and PGP keys to elliptic curve algorithms.

Paragraph Summary

Based on Seth Larson's article and Hacker News discussion, this piece systematically covers how to upgrade SSH and PGP keys from RSA to P-256, ED25519, and Curve25519. It first explains why elliptic curve keys have become mainstream, then provides step-by-step guidance on discovering legacy keys, safely replacing SSH keys (emphasizing the add-first-remove-later order), handling the complexity of PGP key upgrades (involving subkeys and trust network rebuilding), and summarizes common pitfalls around permissions, ssh-agent caching, and deployment keys. It concludes with tiered practical recommendations for individuals and teams, noting that there is no consensus on key rotation frequency.

#SSH key upgrade#PGP key upgrade#ED25519#Curve25519#P-256#elliptic curve cryptography#key rotation
Share:

Related articles