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: openssl genpkey makes Ed25519, EC or RSA keys with one command

Openssl
~/tips/tip-openssl-genpkey-ed25519-ec

openssl genpkey -algorithm ed25519 -out ed.key

Generate any type of private key with the modern genpkey command instead of genrsa.

Old tutorials use genrsa and ecparam -genkey, one command per key type. genpkey covers all of them, and it writes the standard PKCS#8 format.

Pick the algorithm and, where needed, an option for size or curve:

openssl genpkey -algorithm ed25519 -out ed.key
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out ec.key
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out rsa.key

Every file starts with -----BEGIN PRIVATE KEY-----. To see what you made, run openssl pkey -in ec.key -noout -text; it shows the key type and size.

For TLS certificates I would pick P-256: small, fast, and accepted everywhere. Ed25519 is great for signing files and for SSH, but browsers and public CAs do not support it for TLS certificates yet. RSA 2048 is still the safest choice for very old clients, and 3072 bits gives more margin.

The key is written without a passphrase, readable by anyone with access to the file. Run umask 077 first or chmod 600 afterwards, or add a cipher option like -aes256 to encrypt it. Some old software only reads the traditional BEGIN RSA PRIVATE KEY format; openssl rsa -in rsa.key -traditional converts it for those.

Further reading: OpenSSL: openssl-genpkey, OpenSSL: openssl-pkey

More Openssl tips openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null | openssl x509 -noout -subject openssl x509 -in cert.pem -days 365 -signkey key.pem -out cert-new.pem printf %s hello | openssl dgst -sha256 -hmac secret openssl pkcs12 -legacy -in old.pfx -nokeys echo 'aGVsbG8gd29ybGQ=' | openssl base64 -d All Openssl tips (34) All topics

Link