brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl cert and key log in to a server that wants a client certificate

Curl
~/tips/tip-curl-client-certificate

curl --cert client.pem --key client.key https://api.example.com/status

Use your own certificate and key to pass mutual TLS checks on an API or proxy.

Some services check who you are during the TLS handshake instead of with a password. That is mutual TLS, and curl needs your certificate and the matching private key for it.

Give curl both files:

curl --cert client.pem --key client.key https://api.example.com/status

The server checks your certificate against the CA it trusts for clients. Without it, a strict server ends the handshake, and one that only asks for a certificate sees you as anonymous. With nginx in front of a service, the variable $ssl_client_verify then turns from NONE into SUCCESS, which is a handy way to test a new setup.

If your certificate and key sit in one PEM file, --cert alone is enough. A key with a passphrase takes --cert client.pem:passphrase, though I would rather let curl prompt for it than leave it in shell history. For a .p12 file add --cert-type P12.

Keep the key file private with chmod 600: anyone who has it can pass as you until the certificate expires or is revoked. On macOS the system curl uses its own TLS backend, which may handle file names and keychain items differently, so a curl from Homebrew can behave more like the Linux one.

Further reading: curl man page, everything curl: client certificates

Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link