曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
SSH

Your SSH Key May Have Already Expired

SSH keys expired? RSA 2048, still considered secure a decade ago, is now on shaky ground—quantum computing is no joke. Ed25519 is the real deal: short, powerful, and quantum-resistant. Stop treating your ancestral keys like family heirlooms—switch now and set a strong passphrase.

曦远 (DealiAxy)约 21 分钟
目录18 个章节

Preface: Don't Treat Your Keys Like Family Heirlooms

Think back: what year was your ~/.ssh/id_rsa generated?

Have you gone through three computers, still copying this "key" around on a USB drive?

For many developers, the SSH private key is like a family heirloom passed down through generations, accompanying them from their first laptop at graduation, surviving countless OS reinstalls and hardware upgrades.

Yet just as our old-fashioned passwords need to be changed regularly, your SSH key may have expired without you even noticing.

In 2016, when most developers still felt secure owning an RSA 2048-bit key, no one imagined that just a decade later, advances in quantum computing and modern compute power would flash a yellow light on this once absolutely safe standard.

Today, let's re-examine this digital identity we rely on every day but rarely pay attention to.

Primer: Asymmetric Encryption

In Simple Terms

Symmetric encryption means the same password can encrypt and decrypt, just like setting a password on a zip archive.

Asymmetric encryption means encryption and decryption use two different keys.

How It Works

Let's use the metaphor of an envelope and a letter to understand this:

  • Private key: like an important letter, whose content itself is unique
  • Passphrase (SSH Passphrase): like an envelope that protects the letter, providing extra protection
  • Public key: like your bank account number, which you can safely share with anyone

Setting a Passphrase on Your SSH Private Key

When you use the ssh-keygen -p command, you are actually putting a sturdier "envelope" (passphrase) on your "letter" (private key), not rewriting a new letter. This operation does not change the core content of the private key—it is still the same mathematical key pair, just protected by a stronger passphrase.

Key Takeaway

Understanding this is crucial: the passphrase protects the private key file; it does not change the mathematical essence of the private key. Therefore, when you add or change a passphrase on an existing private key, you do not need to update the public key on the server. The public key is still the other half of that exact same key pair and can still verify your identity as usual.

Algorithm Evolution: RSA vs. Ed25519

Why Has RSA Slowed Down?

RSA's security is based on the mathematical difficulty of factoring large numbers, but with the exponential growth of computing power—especially the development of quantum computing—the difficulty of cracking traditional RSA keys is decreasing. An RSA 2048 key that an ordinary computer might have needed centuries to crack a few years ago may, in the face of today's high-end hardware or future quantum computers, have its cracking time shortened to a few hours or even a few minutes.

This contest between compute power and security forces us to re-examine our choice of encryption algorithms. Although RSA is still a widely supported algorithm, its "golden age" is gradually passing.

The New Favorite: Ed25519

Ed25519 is a variant based on the Elliptic Curve Digital Signature Algorithm (ECDSA). Since it was proposed in 2011, it has quickly become the preferred algorithm for SSH keys. It brings several revolutionary advantages:

  1. Shorter length: An Ed25519 private key needs only 64 bytes, while an RSA private key of equivalent security may need 3072 bytes
  2. Faster performance: On most platforms, Ed25519 signing is 4-10 times faster than RSA
  3. Higher security: Elliptic-curve-based Ed25519 is considered more resistant to quantum computing attacks

Comparison Table

FeatureRSA 3072Ed25519
SecurityHigh (but faces quantum computing threats)Very high (better quantum-resistant properties)
Private key length3072 bits (about 384 bytes)64 bytes
Public key length3072 bits (about 768 bytes)32 bytes
Signing speedSlower4-10 times faster
CompatibilityExcellent (SSH protocol 1+2 both supported)Good (SSH protocol 2 supported)
Future outlookGradually being replacedBecoming the new standard

Regenerating Your Keys

Command

If you decide to embrace the future, generate an Ed25519 key and protect it with a sufficiently strong passphrase, you can use the following command:

ssh-keygen -t ed25519 -a 100 -C "your_email@example.com"

Parameter Details

Let's take a closer look at the key parameters in this command:

  • -t ed25519: specifies the Ed25519 algorithm, one of the most secure SSH key types today
  • -a 100: this is the most easily overlooked yet extremely important parameter; it specifies the number of rounds for the key derivation function (KDF)
  • -C "your_email@example.com": adds a comment so you can identify what this key is for

What is KDF rounds? Simply put, it is a trick for "slowing down" hackers. When you set a passphrase on a private key, the system uses a KDF to convert your passphrase into a real encryption key. The -a 100 parameter tells SSH to perform 100 rounds of iterative computation during this conversion.

Why does this matter? Because more iterations mean more computational resources are needed to brute-force your passphrase. If your private key is stolen, even if attackers obtain the private key file, they still cannot use it without the correct passphrase. And 100 rounds of iteration means they need to try 100 computations to verify a single possible passphrase combination, greatly increasing the difficulty of cracking.

Easter Egg: Visual Host Key

After generating the key, you will see a character matrix similar to the following:

+--[ED25519 256]--+
|       .o.       |
|      .  o+      |
|     o . = .     |
|    . . B o      |
|     . S * .     |
|      o B .      |
|     . = * |
|      + @ o      |
|     . E * |
+----[SHA256]-----+

This is called a Visual Host Key. It was designed so humans can quickly compare with their eyes: if the picture you see on a given login looks different from usual, you may be facing a man-in-the-middle attack (MITM).

However, most server systems no longer display this pattern on connect. To show it, you can specify:

ssh -o VisualHostKey=yes user@your-server-ip

Or edit your local ~/.ssh/config

Host *
    VisualHostKey yes

Smooth Migration

Multiple Keys Coexisting

Upgrading does not mean you have to completely abandon the past. SSH supports coexisting key files, so you can use old keys and new keys at the same time. By configuring the ~/.ssh/config file, you can specify different keys for different connections:

# 为github.com使用ed25519密钥
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes

# 为老服务器保留RSA密钥
Host old-server.example.com
  HostName old-server.example.com
  User your_username
  IdentityFile ~/.ssh/id_rsa

With the IdentitiesOnly yes directive, SSH will try these keys in the specified order rather than blindly trying all available keys, which both improves security and simplifies the connection process.

One-Click Deployment

After you generate a new key, you need to add the corresponding public key to all servers you need to access. The simplest method is to use the ssh-copy-id command:

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@remote-server

This command automatically adds your public key to the remote server's ~/.ssh/authorized_keys file and sets the correct permissions. For bulk deployment, you can write a simple script to loop through this process.

Conclusion

In today's rapidly changing technology landscape, keeping your toolchain up to date is no longer merely a technical pursuit, but a matter of professional integrity for every developer. Your SSH key is the key to your digital world; it protects your code, your data, and your online identity.

Just as we would not leave our house keys under the doormat, we should not neglect the security and timeliness of our SSH keys. Regularly review your key configuration, embrace more secure algorithms, and set stronger passphrase protection—these seemingly small actions can build a solid line of defense for your digital security.

_EOF_

Your SSH Key May Have Already Expired

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

Asp-Net-Core学习笔记:部署,早知道,还是docker,以及一点碎碎念

前言 AspNetCore技术栈在我们团队里的使用也有一段时间了,之前的部署方式一直是本地编译之后上传可执行文件到服务器,使用supervisor来管理进程这种很原始的方式。 参考之前的文章: 对于小项目来说尚可,够用,但是存在几个问题: 每次更新花费的时间太长了,无论是Framework-Dependent还是Self-Contained,都要上传很大的文件~ 更新的时候需要在superviso

2022-02-16 · Asp-Net-Core学习笔记 · 约 1 分钟

Spring-Boot:创建第一个应用

简介 Spring Boot 是一个轻量级框架,可以完成基于 Spring 的应用程序的大部分配置工作。在本教程中,将学习如何使用 Spring Boot 的 starter、特性和可执行 JAR 文件结构,快速创建能直接运行的基于 Spring 的应用程序。 本文使用IDEA作为开发工具,Gradle作为构建工具,创建一个简单的SpringBoot应用,暂时不涉及数据库的配置。 使用IDEA创建

2022-05-27 · Java · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…