Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

wget fails certificate verification when a script downloads a file

Errorwget --no-check-certificate error

Short answer

wget verifies the server certificate against its CA bundle and exits with status 5 when that check fails. Find out who signed the certificate. If it is a private CA, give wget that CA with --ca-certificate. Use --no-check-certificate only for a host you control, because it turns off the check.

  • Applies to GNU Wget 1.21, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the download once by hand and read the exit status. Status 5 is the SSL verification failure.

    wget -O /tmp/data.csv https://example.com/data.csv
    echo "exit status: $?"
  2. 2Match what you see, then jump to its fix

    1. 1The site works only on your network, and its certificate was issued by your own organisation or a staging setupThe certificate comes from a private or internal CAFix
    2. 2The certificate is self-signed or expired on a host you operate, and you cannot fix it right nowA one-off download from a host you trust, where the certificate is simply wrongFix

What does the error look like?

  • wget --no-check-certificate error
  • SSL verification failure (exit status 5)

Cause 1 of 2

The certificate comes from a private or internal CA

1Check

A private CA is not in the system bundle, so verification fails. Get the CA certificate file from whoever runs the server.

openssl s_client -connect example.com:443 -showcerts </dev/null | head -40

2Fix

Point wget at that CA file, or at a directory of CA certificates in PEM format. This keeps the check on.

wget --ca-certificate=/etc/ssl/private-ca.pem -O /tmp/data.csv https://example.com/data.csv

# or a directory of PEM CA files
wget --ca-directory=/etc/ssl/my-cas -O /tmp/data.csv https://example.com/data.csv

3Verify

The download finishes and the exit status is 0.

wget --ca-certificate=/etc/ssl/private-ca.pem -O /tmp/data.csv https://example.com/data.csv
echo $?

Confirmed by manpages.debian.org

Did this fix it?

Cause 2 of 2

A one-off download from a host you trust, where the certificate is simply wrong

1Check

wget's manual calls skipping the check almost always a bad idea for confidential or important data, and says to use it only when you are convinced of the site's authenticity.

openssl s_client -connect example.com:443 -showcerts </dev/null

2Fix

Use --no-check-certificate temporarily for that one host, then replace the certificate. Do not leave it in a script that downloads data from the internet.

wget --no-check-certificate -O /tmp/data.csv https://staging.example.com/data.csv

3Verify

The file downloads. Then renew the certificate and remove the flag.

wget -O /tmp/data.csv https://staging.example.com/data.csv; echo $?

Confirmed by manpages.debian.org

Did this fix it?

How do I stop it coming back?

  • In cron jobs, test the exit status of wget and send an alert when it is not 0.
  • Keep the private CA file in version control or config management so every server trusts the same one.
  • Monitor certificate expiry dates on the hosts you operate.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Back end

CodeIgniter 4 cannot write its cache files

CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/

CodeIgniter 4's file cache needs a cache directory that the web server can really write to.

2 causes, each with a fix

Back end

CodeIgniter 3 loads the model but the property is undefined

The model name you are loading is the name of a resource that is already being used: user

CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.