TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Drop SSH private keys in exchange for keygen via PRNG and Ed25519

2 点作者 imcotton大约 1 年前
(tldr; visit https:&#x2F;&#x2F;jsr.io&#x2F;@key&#x2F;gen-ssh-ed25519 for details)<p>I have a hot take: the ~&#x2F;.ssh folder should NOT contain private keys.<p>A private key is generated on the first day of computer setup and remains there permanently. It will have mode 600 if not misconfigured, and may also have a passphrase for protection (you do ... do you?). So, what&#x27;s the catch?<p>During its entire lifespan, which can be months or even years, those private keys can be compromised in just a matter of seconds. This could happen if someone types &quot;curl -d&quot; in the command line on your behalf during a coffee break, or if an NPM package with numerous intermediate dependencies&#x27; postinstall scripts to send it elsewhere, even if guarded by a passphrase, ask yourself how confident you are that phrase you have will survive offline brute-force attacks?<p>ssh-agent to the rescue.<p>If you&#x27;ve enabled AddKeysToAgent and UseKeychain in your ~&#x2F;.ssh&#x2F;config file, you can safely remove your private key from the disk after it&#x27;s automatically added to the ssh-agent (verify by ssh-add -L). This protects against all kinds of attacks, however, if you reboot your system, you&#x27;ll need to set everything up again.<p>Thus the reproducible keygen comes into play, in a nutshell, instead of relying on entropy taken from &#x2F;dev&#x2F;random and letting the end user hold on to it safely forever (how?), let&#x27;s use well-configured PRNG (i.e. PBKDF2 - SHA512 - 400,000 rounds in 2024 from native webcrypto in this case) with better algos (Ed25519 instead of RSA), to generate the same private key on demand on-the-fly, once the private key added onto ssh-agent, then just delete it from the disk, this greatly reduced the attack surface of the private key, no private key left means nothing to leak at the first place.<p>The last piece of the puzzle is coming up with a manageable salt&#x2F;passphrase for PRNG, this can vary depending on your threat modeling, I will provide a few examples for inspiration, but you should choose what works best for you:<p>- UUID generated from system entropy, put into ~&#x2F;.ssh&#x2F;config as a vague comment yet you can retrieve it later on<p>- a strong password generated by password managers and safely stored across multiple devices<p>- any git commit hash that is unrelated whatsoever, this can come from one of your side projects or even some opensource project, as long as you don&#x27;t lose the trace from your mental memory<p>- Merkle tree root hash from any given height of the blockchain<p>- specific version of any pkg (i.e. npm or crates) tarball&#x27;s checksum<p>- your favorite number multiplied by the year of choice and cubed, i.e. (42 * 2024) ^ 3<p>- chunk of pi digits<p>etc...<p>The program is released on JSR (https:&#x2F;&#x2F;jsr.io&#x2F;@key&#x2F;gen-ssh-ed25519) and designed to be executed by Deno which is secure by default, it reads from command args and emits to stdout, without any file, network, or environment access.<p>Credit to Paul Miller by his NPM package (https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;ed25519-keygen) for the heavy lifting.<p>What is your opinion? Do you have any other suggestions or did you notice any oversights?

2 条评论

Dibby053大约 1 年前
There used to be a website that provided an easy way to derive bitcoin addresses from passwords. Random people would routinely send bitcoin to wallets with passwords like &quot;123456&quot;, &quot;correct horse battery staple&quot;, digits of pi and so on only to see their coins stolen by bots in a matter of miliseconds.<p>This is not as bad but people will inevitably use bad passwords if given the option so it&#x27;s better not to make things too easy for them in my humble opinion.
dave4420大约 1 年前
I keep my private keys stored in my password manager.