Application 2024-02-16

One-Liner for Self-Signed Certificates in Go

Generate a self-signed TLS certificate in Go with one command using the built-in generate_cert.go tool. Produces cert.pem and key.pem for local HTTPS without openssl or mkcert.

Read in: ja
One-Liner for Self-Signed Certificates in Go

A handy one-liner for when you need a self-signed certificate while writing an HTTP server in Go.

go run $(go env GOROOT)/src/crypto/tls/generate_cert.go -rsa-bits 2048 -host localhost

This will generate cert.pem and key.pem.

I used to rely on openssl or mkcert, but this seems to work well when using Go.

cf. Source file src/crypto/tls/generate_cert.go

Tags: Golang Tips
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles