Curl Ignore Certificate Checks Example

-k tells curl to proceed even though it cannot verify who it is talking to. It makes the error go away, which is not the same as making the connection safe.

Last updated . How this page is checked.

The command

curl -k https://self-signed.badssl.com/

What the flags do

FlagWhat it does
-kSkip certificate verification. Long form: --insecure.
--cacert fileThe alternative: trust a specific CA or self-signed certificate.
--proxy-insecureThe same switch for the connection to an HTTPS proxy.

What -k turns off

With -k, curl accepts any certificate: self-signed, expired, issued for a different hostname, or signed by nobody recognisable. The connection is still encrypted, but encryption without authentication protects you only from passive eavesdroppers. Anyone able to intercept the connection can present their own certificate, and curl will send them your request, headers and credentials without complaint.

It is reasonable for a throwaway request to a local development server or a device on your desk. It is not reasonable in a script, a CI job, a Dockerfile or documentation that others will copy.

curl https://self-signed.badssl.com/      # curl: (60) SSL certificate problem
curl -k https://self-signed.badssl.com/   # works, unverified

Fix the trust instead

For a self-signed development certificate, hand curl that certificate as the trusted root and verification passes for real. For a company CA, do the same with the CA file. For the wrong hostname on a test machine, --resolve lets you use the proper name. Each of these keeps the check that -k throws away.

# trust exactly this self-signed certificate
curl --cacert dev-cert.pem https://localhost:8443/

# fetch a server's certificate to inspect it
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates

Common mistakes

  • insecure in ~/.curlrc disables verification for every curl command you ever run. If it is there, remove it.
  • -k does not fix protocol errors. A handshake failure (exit code 35) is not a certificate problem and -k changes nothing.
  • It hides real incidents. A certificate that expired last night and a hijacked connection look identical once verification is off.

Related curl examples

More under HTTPS and TLS

References

These links leave api-tester.com, which is independent of the projects they point to.

FAQ

How do I make curl ignore SSL certificate errors?

Add -k (or --insecure). Curl then skips TLS certificate verification and connects even when the certificate is self-signed, expired or issued for a different hostname.

Is it safe to use curl --insecure?

Only against servers you control on a network you trust, such as local development. Elsewhere it exposes the request to interception, because the server identity is not checked.

How do I make curl trust a self-signed certificate without -k?

Pass the certificate with --cacert file.pem. Curl then verifies the connection against it.