wget fails certificate verification when a script downloads a file
wget --no-check-certificate errorShort 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.
Fix it fast
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: $?"2Match what you see, then jump to its fix
- 1
The 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
The 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
- 1
What does the error look like?
wget --no-check-certificate errorSSL 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 -402Fix
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.csv3Verify
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
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/null2Fix
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.csv3Verify
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
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
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack 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 fixBack 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