Getting Chrome to Accept Self-signed Localhost Certificate
To get Chrome to accept a self-signed SSL certificate for localhost
, you'll need to add the certificate to the system's trusted root certificate store. Here's how to do it:
Step 1: Generate a Self-signed Certificate for localhost
Follow the steps below to generate a self-signed certificate specifically for localhost
.
Generate the Private Key:
openssl genpkey -algorithm RSA -out localhost.key -aes256
Create a Certificate Signing Request (CSR):
openssl req -new -key localhost.key -out localhost.csr
When prompted, make sure to set the Common Name (CN) to
localhost
.Generate the Self-signed Certificate:
openssl x509 -req -days 365 -in localhost.csr -signkey localhost.key -out localhost.crt
Step 2: Install the Certificate in the Trusted Root Certificate Store
On Windows:
- Double-click the
localhost.crt
file. - Click on the "Install Certificate" button.
- Choose "Local Machine" and click "Next."
- Select "Place all certificates in the following store" and browse to "Trusted Root Certification Authorities."
- Complete the wizard by clicking "Next" and "Finish."
- Restart Chrome to apply the changes.
On macOS:
- Open the Keychain Access application.
- Drag and drop the
localhost.crt
file into the System keychain or login keychain. - Right-click the certificate and select Get Info.
- Expand the "Trust" section and set "When using this certificate" to Always Trust.
- Close the window, and you may be prompted to enter your password to confirm the changes.
- Restart Chrome to apply the changes.
On Linux:
Copy the certificate to the
/usr/local/share/ca-certificates/
directory:sudo cp localhost.crt /usr/local/share/ca-certificates/localhost.crt
Update the CA certificates:
sudo update-ca-certificates
Restart Chrome to apply the changes.
Step 3: Accessing localhost
with HTTPS in Chrome
Now that the certificate is trusted, you should be able to access https://localhost
in Chrome without receiving a certificate warning.
If you still see a warning, you might need to clear your browser's cache or reset Chrome's SSL state:
- Go to
chrome://net-internals/#ssl
. - Click the "Clear SSL state" button.
- Restart Chrome.
This process ensures that Chrome will accept your self-signed certificate for localhost
, allowing you to develop securely using HTTPS.
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usBuild on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github