• DEV
  • [macOS] Create localhost SSL certificate (to setup HTTPS)

[macOS] Create localhost SSL certificate (to setup HTTPS)

By TidusLast update: 2024-05-03

Open Terminal

1. Create SSL folder to store SSL files

mkdir ssl

cd ssl

2. Create SSL CSR & private key

You can use any file name here (just replace localhost)

openssl req -new -newkey rsa:2048 -nodes -keyout localhost.key -out localhost.csr

Enter info as below. Note: change localhost to your localhost domain name (ex: www.domain.name)

Country Name (2 letter code) [AU]:VN

State or Province Name (full name) [Some-State]:HCM

Locality Name (eg, city) []:HCM

Organization Name (eg, company) [Internet Widgits Pty Ltd]:VN

Organizational Unit Name (eg, section) []:VN

Common Name (e.g. server FQDN or YOUR name) []:localhost

Email Address []:[email protected]

There are 2 more infos may be asked:

  • A challenge password
  • An optional company name

Leave these info BLANK (just Enter, no need input anything)

3. Create .ext file

touch localhost.ext

Copy & paste below content to v3.ext file

Note: change localhost to your localhost domain name

authorityKeyIdentifier=keyid,issuer

basicConstraints=CA:FALSE

keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment

subjectAltName = @alt_names

[alt_names]

DNS.1 = localhost

4. Create SSL CRT

openssl x509 -req -sha256 -extfile localhost.ext -days 3650 -in localhost.csr -signkey localhost.key -out localhost.crt

5. Add SSL CRT to macOS Keychain

  • Double click on localhost.crt on Finder
  • Select Keychain: System then click Add
[macOS] Create localhost SSL certificate (to setup HTTPS)
  • Find & double click on localhost cert in Keychain Access
  • Expand Trust, select When using this certificates: Always Trust
[macOS] Create localhost SSL certificate (to setup HTTPS)
  • Close the window and click Update Settings

Done!


Related Articles

    Tidus' Blog