Technotes for future me


Check certificate

curl --insecure -v 2>&1 | awk 'BEGIN { cert=0 } /^\* SSL connection/ { cert=1 } /^\*/ { if (cert) print }'

Connect via proxy

-x, –proxy <[protocol://][user:password@]proxyhost[:port]>
Use the specified HTTP proxy. If the port number is not specified, it is assumed at port 1080.

This option overrides existing environment variables that set the proxy to use. If there’s an environment variable setting a proxy, you can set proxy to "" to override it.

All operations that are performed over an HTTP proxy will transparently be converted to HTTP. It means that certain protocol specific operations might not be available. This is not the case if you can tunnel through the proxy, as one with the -p, –proxytunnel option.

User and password that might be provided in the proxy string are URL decoded by curl. This allows you to pass in special characters such as @ by using %40 or pass in a colon with %3a.

The proxy host can be specified the exact same way as the proxy environment variables, including the protocol prefix (http://) and the embedded user + password.

From 7.21.7, the proxy string may be specified with a protocol:// prefix to specify alternative proxy protocols. Use socks4://, socks4a://, socks5:// or socks5h:// to request the specific SOCKS version to be used. No protocol specified, http:// and all others will be treated as HTTP proxies.

If this option is used several times, the last one will be used.

curl -kx https://proxyhost:3128


-k, –insecure
(SSL) 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.
This makes all connections considered “insecure” fail unless -k, –insecure is used.

curl -vk -H "Host:" -H "X-Forwarded-Proto: https"


curl > centos-org.html

Follow HTTP Location Headers with -L option

curl -L

Download a file only if it is modified before/after the given time

curl -z 21-Dec-11

Pass HTTP Authentication in cURL

curl -u username:password URL

View only headers with Curl

curl -I -X GET

Provide hostname

curl -vk -H "Host:" -H "X-Forwarded-Proto: https"

Provide a custom address for a specific host and port pair

Using this, you can make the curl requests(s) use a specified address and prevent the otherwise normally resolved address to be used.
Consider it a sort of /etc/hosts alternative provided on the command line.
The port number should be the number used for the specific protocol the host will be used for.
It means you need several entries if you want to provide address for the same host but different ports.

curl --resolve --insecure

Provide header

curl -vk -H "X-Forwarded-Proto: https"

Provide User Agent

curl -vk -H "User-Agent: user-Agent-Name-Here"


curl -g -6 'http://[2a00:1d38:f8::6]:80/'


curl --user user:pass --cookie-jar ./somefile
curl --cookie ./somefile

timeout test

# Check certificate expiry
for url in
  echo "${url}"
  curl --insecure -vm 2 https://"${url}" 2>&1 | awk 'BEGIN { cert=0 } /^\* SSL connection/ { cert=1 } /^\*/ { if (cert) print }' | grep -e subject -e date

  if test "$res" != "0"; then
    echo "the curl command failed with timeout"
    read -n 1 -s -r -p "Press any key to continue"
    echo ""

Last updated on 19 Oct 2022
Published on 11 Dec 2019
Edit on GitHub