Skip to content

How to ignore invalid and self-signed certificates using cURL

When cURL refuses a connection because a certificate is expired, self-signed, or signed by an untrusted authority, the -k option tells cURL to continue anyway.

OUTPUT FORMATSHTMLJSONMarkdown

That is convenient for local testing, but it removes the protection that certificates normally provide. This guide shows the exact command, explains what each failure means, and gives a checklist for choosing between bypassing the check and repairing trust.

The command

Pass -k to cURL before the URL. The sample below sends a GET request to the hosted HTTPBin endpoint with certificate verification disabled.

What -k actually does

-k (also written --insecure) tells cURL not to validate the server certificate chain. cURL will still perform the TLS handshake, but it will not reject a certificate because it is expired, not yet valid, signed by an untrusted CA, missing a trusted root, or using a weak signature algorithm. Because the identity of the server is no longer checked, an attacker positioned between you and the server can present their own certificate and read or alter traffic. Treat -k as a debugging aid for test systems, not a production setting.

Self-signed vs. invalid certificates

A self-signed certificate is one that is not signed by a trusted certificate authority. It is common on internal test servers and is sometimes called a fake certificate because no external CA vouches for it. An invalid certificate is broader: it may be expired, not yet valid, signed by an untrusted CA, part of a chain that does not end at a trusted root, or signed with a weak algorithm such as MD5 or SHA1. The -k flag suppresses all of these checks at once, which is why it is a blunt tool.

Decision checklist

Use this checklist before adding -k:

  1. Is the endpoint a local or isolated test server? If yes, -k may be acceptable for the duration of the test.
  2. Is the certificate self-signed on purpose? If yes, consider trusting that certificate explicitly instead of disabling verification globally.
  3. Is the failure caused by an expired or not-yet-valid certificate? Fix the certificate dates rather than bypassing the check.
  4. Is the chain missing a trusted root? Install the correct root or intermediate certificate.
  5. Is the signature algorithm weak? Replace the certificate with one using a modern algorithm.
  6. Is this production traffic? Do not use -k; repair trust instead.

If you cannot answer yes to the first question, prefer fixing the certificate over disabling verification.

Failure distinction map

cURL reports different errors depending on why verification failed. The table below maps the captured failure reasons to the appropriate response.

Example with the hosted HTTPBin endpoint

The captured sample uses the hosted HTTPBin base URL. In a test environment you would run:

curl -k {{HTTPBIN_BASE_URL}}

This sends a GET request without certificate validation. If the same command fails without -k, the error message will indicate which of the failure reasons above applies. Use that message to decide whether to trust the certificate explicitly or to repair it.

Related cURL tasks

Other common cURL operations include sending a GET request, using Basic Auth, posting JSON, downloading a file, following redirects, retrieving JSON or XML, sending a DELETE request, and setting HTTP headers. These are separate tasks from certificate handling and are linked in the related questions section.

Certificate failure reasons and recommended response
Failure reasonRecommended response
The certificate is expiredRenew the certificate; do not use -k in production.
The certificate is not yet validCheck the system clock and certificate validity dates.
The certificate is signed by an untrusted CAInstall the correct CA certificate or use a certificate from a trusted CA.
The chain doesn’t end with a trusted root certificateAdd the missing intermediate or root certificate to the trust store.
The site only uses a weak signature algorithm (MD5, SHA1, etc.)Replace the certificate with one using a modern signature algorithm.

Failure reasons are taken from the captured reference; exact error text varies by cURL version and platform.

Frequently asked questions

What does the -k option do in cURL?

It disables certificate verification, so cURL will proceed even if the certificate is expired, self-signed, signed by an untrusted CA, or otherwise invalid. It does not encrypt traffic differently; it only skips the identity check.

Is it safe to use -k in production?

No. Skipping certificate verification makes the connection vulnerable to man-in-the-middle attacks because the server's identity is not confirmed. Use -k only for testing, and repair the certificate trust chain for production traffic.

What is a self-signed certificate?

A certificate that is not signed by a trusted certificate authority. It is often used on internal test servers and is not trusted by default by cURL or browsers.

Why does cURL say the certificate is invalid?

Common reasons include an expired certificate, a certificate that is not yet valid, an untrusted CA, a chain that does not end at a trusted root, or a weak signature algorithm such as MD5 or SHA1.

curl -k {{HTTPBIN_BASE_URL}}