82

How to easily create self signed SSL certificate for testing purposes?

1
  • Please use the search, this should have been asked and answered already, if not search the other stackoverflow Q&A sites, too please // close-votes but nobody suggested a duplicate - there ain't one?
    – hakre
    Jan 10, 2013 at 23:47

1 Answer 1

125

You can do this via openssl:

  1. Install openssl package (if you are using Windows, download binaries here).

  2. Generate private key: openssl genrsa 2048 > private.pem

  3. Generate the self signed certificate: openssl req -x509 -days 1000 -new -key private.pem -out public.pem

  4. If needed, create PFX: openssl pkcs12 -export -in public.pem -inkey private.pem -out mycert.pfx

11
  • 34
    As a one-liner: openssl req -new -x509 -nodes -out server.crt -keyout server.key
    – Alex
    Mar 19, 2014 at 20:24
  • 2
    Must add -sha256 to avoid more errors
    – Alex G
    Sep 24, 2016 at 19:43
  • 4
    The link to the Windows binaries above doesn't work anymore. Openssl.org does not provide any binaries themselves but the do offer a list to binaries in their wiki.
    – klaas
    Oct 11, 2016 at 15:41
  • 7
    For Windows users: Git Bash includes openssl. I thick Git is one of must have things in developer's system ^)
    – kyb
    Jan 30, 2018 at 21:40
  • 1
    For windows, you could find it at "C:\Program Files\Git\usr\bin\openssl.exe"
    – John Jang
    Oct 12, 2020 at 0:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.