DEV Community

Cover image for One-Liner for Self-Signed Certificates in Go
Kenta Takeuchi
Kenta Takeuchi

Posted on • Originally published at bmf-tech.com

One-Liner for Self-Signed Certificates in Go

This article was originally published on bmf-tech.com.

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)