How to easily create self signed SSL certificate for testing purposes?
Asked
Active
Viewed 7.2k times
77
-
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 '13 at 23:47
1 Answers
115
You can do this via openssl:
Install openssl package (if you are using Windows, download binaries here).
Generate private key:
openssl genrsa 2048 > private.pemGenerate the self signed certificate:
openssl req -x509 -days 1000 -new -key private.pem -out public.pemIf needed, create PFX:
openssl pkcs12 -export -in public.pem -inkey private.pem -out mycert.pfx
Chris Stryczynski
- 25,295
- 38
- 135
- 245
Dima Stopel
- 2,297
- 2
- 16
- 12
-
28As a one-liner: openssl req -new -x509 -nodes -out server.crt -keyout server.key – Alex Mar 19 '14 at 20:24
-
1
-
3The 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](https://wiki.openssl.org/index.php/Binaries). – klaas Oct 11 '16 at 15:41
-
You can download cygwin for openssl for windows and check openssl from tools. – user1626116 Mar 13 '17 at 23:48
-
5. `openssl pkcs12 -in mycert.pfx -out mycert.pem -nodes` to create mycert.pem certificate (for example needed by jupyter) from .pfx, as according to [this document.](http://webhelp.evisions.com/HelpFiles/MAPS/en/Content/OpenSSL%20Certificates.htm) – macieksk Jan 04 '18 at 16:05
-
5For Windows users: **Git Bash** includes `openssl`. *I thick Git is one of must have things in developer's system* ^) – kyb Jan 30 '18 at 21:40
-
1For windows, you could find it at "C:\Program Files\Git\usr\bin\openssl.exe" – John_J Oct 12 '20 at 00:48
-
On Win10 I was running this from git bash -- Generating public works. Attempting to generate pfx seemed to hang. It's related to git bash problem when getting password -- the fix is to prefix openssl command with $ winpty openssl... See https://stackoverflow.com/questions/34156938/openssl-hangs-during-pkcs12-export-with-loading-screen-into-random-state for more info. – raddevus May 05 '21 at 14:39
-