brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ssh-keygen -p changes a key's passphrase without a new key

Network and access
~/tips/tip-ssh-keygen-p-change-passphrase

ssh-keygen -p -f ~/.ssh/id_ed25519

Adds, changes or removes the passphrase on an existing SSH private key.

If you once made an SSH key without a passphrase, or with one you’d rather change, you don’t have to make a new key and copy it to every server again. ssh-keygen can change the passphrase of the key you already have.

ssh-keygen -p -f ~/.ssh/id_ed25519

-p asks to change the passphrase of a private key file instead of creating a new key, and -f points at the key. It prompts for the old passphrase (just press Enter if there was none) and then twice for the new one. The key itself stays the same, so the servers that trust it don’t notice anything.

While you’re at it, you can raise the work factor of the passphrase protection. The man page says changing the passphrase re-encrypts the key, and -a sets the number of KDF rounds:

ssh-keygen -p -a 100 -f ~/.ssh/id_ed25519

More rounds make guessing the passphrase of a stolen key file slower. The cost is a tiny delay each time you unlock the key.

Caveats: there’s no way to recover a lost passphrase, as the man page puts it, so store the new one in your password manager before you close the terminal. And while -P and -N let you pass the old and new passphrase on the command line, I’d let it prompt: a passphrase you type as an argument can end up in your shell history.

Further reading: OpenBSD manual: ssh-keygen(1)

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link