≡ Menu

How to ignore invalid and self singed ssl connection errors with curl command

I wanted to curl command to ignore SSL certification warning. Does curl command have a --no-check-certificate option like wget command on Linux or Unix-like system?

You need to pass the -k or --insecure option to the curl command. This option explicitly allows curl to perform “insecure” SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default.

Syntax

The syntax is:

curl -k url
curl --insecure url
curl --insecure [options] url
curl --insecure -I url

cURL ignore SSL certificate warnings command

In this example disable certificate verification for curl command:
curl --insecure -I https://202.54.1.2/
OR
curl -k -O https://202.54.1.2/file.tar.gz
Without the -k or --insecure option, you will get an error message that read as follows:

curl: (60) SSL certificate problem: Invalid certificate chain
More details here: https://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

Here is one useful example where you want to grab a file or see header info from remote host without using SSL enabled SNI domain name:

curl -O --insecure --header 'Host: www.example.com' -I https://207.5.1.10/file.html
### OR ###
curl -k --header 'Host: www.example.com' -I https://207.5.1.10/file.html

Sample outputs:

Fig.01: Ignoring certificate warnings and saving the page or getting header info using curl command

Fig.01: Ignoring certificate warnings and saving the page or getting header info using curl command


You can add insecure to your $HOME/.curlrc file:
$ vi $HOME/.curlrc
Append the following:

insecure

Save and close the file. However, I do not recommend disabling SSL checks for all connections by default for security reasons.

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 1 comment… add one }
  • Tricky February 24, 2017, 6:36 am

    I think it is important, whilst you are setting up your own services, to be able to connect even though you haven’t yet set up a proper certificate. With LetsEncrypt though, having curl permanently ignore security is particularly lazy.

    The alternative of course is having your system trust your own CA.

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , ,