SSH Key Generator

One input per line. Output is numbered to match the input order.
Pinned tools are listed in your favourites on the home page.Copies a link to this tool that carries your current input, so it opens ready to run.Gives you an iframe snippet for putting this tool on your own site.
Ctrl+Enter Run  · Ctrl+Shift+C Copy  · Esc Clear

Understand SSH Key Generator

在你的浏览器中生成一对 RSA(2048 或 4096 位)或 Ed25519 密钥,并同时给出 OpenSSH 格式与 PEM 格式的公钥。

How it works

crypto.subtle.generateKey 用平台的 CSPRNG 生成密钥对,随后把私钥导出为 PKCS#8、公钥导出为 SPKI,各自以 base64 包裹在 PEM 头尾行之间。RSA 的安全性建立在分解模数的代价之上,这就是密钥需要 2048 或 4096 位的原因;Ed25519 在 256 位曲线上达到相当的强度,公钥仅 32 字节,签名也快得多。公钥还会以 OpenSSH 传输格式输出——一段带长度前缀、包含算法名和密钥字段的数据块,以 base64 编码成一行——这正是 authorized_keys 和 GitHub 密钥输入框所期望的形式。当浏览器的 WebCrypto 不支持 Ed25519 时,工具会回退到 P-256 上的 ECDSA,并在输出中如实说明,而不是给结果贴错标签。

When to use it

  • 为实验环境、容器镜像或测试夹具生成一次性密钥对。
  • 取得 PEM 公钥,交给需要验证签名的服务,例如 RS256 JWT 的消费方。
  • 在学习密钥格式时,查看 PKCS#8 和 SPKI 里究竟包含什么。
  • 在无法安装或运行 OpenSSH 的机器上生成密钥。
  • 并排比较 RSA-2048、RSA-4096 和 Ed25519 的输出长度。

Watch out for

  • 这里给出两种格式,它们不可互换。以 ssh-rsa 或 ssh-ed25519 开头的 OpenSSH 单行内容用于 authorized_keys 和 GitHub 密钥框;PEM 块则通常是验证签名的库所需要的。粘错了会在对端得到一条毫无帮助的错误信息。
  • 这里的私钥没有口令保护。在本地运行 ssh-keygen 会提示对静态密钥加密;而这里是明文导出,因此任何能读到页面或剪贴板的东西都能拿走一把可用的密钥。
  • 在 WebCrypto 不支持 Ed25519 的浏览器上,请求「Ed25519」可能返回 ECDSA P-256。工具报告的是它实际生成的算法,而不是你请求的那个,因此在依赖密钥类型之前请先读那一行。
  • RSA-2048 仍然可以接受,但对长期使用的密钥而言 4096 是更保守的选择,而 Ed25519 比两者都更小更快。OpenSSH 自 2014 年的 6.5 版起就支持 Ed25519,因此如今兼容性很少再是决定因素。

Not the right tool for: 保护真实基础设施的密钥。那些请在本地用 ssh-keygen -t ed25519 -C "[email protected]" 生成,私钥会带口令直接写入 ~/.ssh,并且从不曾出现在浏览器标签页里。

Frequently Asked Questions

如何生成 SSH 密钥?

选择 Ed25519(推荐)或 RSA 2048/4096,可选填写一段注释(例如你的邮箱),然后点击生成。密钥使用 WebCrypto API 在你的浏览器中创建,不会被发送到任何地方。你会得到用于服务器的 OpenSSH 公钥,以及两把密钥的 PEM 副本。

如何为 GitHub 生成 SSH 密钥?

生成一对 Ed25519 密钥,复制 OpenSSH 公钥——即以 ssh-ed25519 开头的那一行——然后在 GitHub 中依次打开 Settings、SSH and GPG keys、New SSH key,把它粘进去。把 PEM 私钥保存为 ~/.ssh/id_ed25519 并执行 chmod 600,然后用 ssh -T [email protected] 测试

如何在 Windows 上生成 SSH 密钥?

使用这个浏览器工具(无需安装软件),或者打开 PowerShell 运行:ssh-keygen -t ed25519 -C "your_email"。密钥会保存到 C:\Users\YourName\.ssh\。公钥(id_ed25519.pub)就是你要添加到远程服务器和 GitHub 上的那一个。

How to Use SSH Key Generator

  1. Paste or type your input in the input area above.
  2. The tool processes your input automatically or click Run.
  3. Copy or download the result using the action buttons.
  4. Use Ctrl+Enter to run quickly from the keyboard.