Skip to content

Instantly share code, notes, and snippets.

@Anubisss
Last active August 13, 2021 09:10
Show Gist options
  • Save Anubisss/a5a641998350a44768f54203d27f6f88 to your computer and use it in GitHub Desktop.
Save Anubisss/a5a641998350a44768f54203d27f6f88 to your computer and use it in GitHub Desktop.
How to create SSL certificate for localhost development on macOS

How to create SSL certificate for localhost development on macOS

  1. Generate the private key and the certificate
openssl req -x509 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost' -extensions EXT -config <( \
  printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
  1. Make the OS to trust this certificate
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain localhost.crt

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment