Some authenticated downloads are easiest to reproduce by replaying the exact cookies already issued by the target site. wget can send those values either from a Netscape-format cookie jar or from a raw Cookie: request header, which is useful for short validation runs and browser-to-CLI handoffs.
The safer method is --load-cookies because wget honors the stored domain, path, expiry, and secure flags for each cookie. The lighter method is --header="Cookie: ...", which injects the cookie string exactly as written and bypasses the normal jar matching logic. GNU wget documentation still treats the raw header approach as the fallback when a usable Netscape cookie file cannot be produced.
Custom cookies are still credentials. Keep the jar or header value out of shared directories, prefer short-lived sessions, and confirm the protected response body before using the result in a larger automation chain.
Related: How to save session cookies in wget
Related: How to send custom headers with wget
$ mkdir -p "$HOME/wget-custom-cookies" $ cd "$HOME/wget-custom-cookies"
Isolation makes it easier to review, rotate, and remove cookie data when the task is complete.
$ cat > custom-cookies.txt <<'EOF' # HTTP Cookie File # Generated for wget custom cookie test. httpbin.org FALSE / FALSE 0 auth_token A1B2C3D4E5 httpbin.org FALSE / FALSE 0 sessionid xyz123session EOF
Browser cookie-export tools usually produce this same format, so manual editing is only needed when a small test jar is enough.
$ chmod 600 custom-cookies.txt $ sed -n '1,8p' custom-cookies.txt # HTTP Cookie File # Generated for wget custom cookie test. httpbin.org FALSE / FALSE 0 auth_token A1B2C3D4E5 httpbin.org FALSE / FALSE 0 sessionid xyz123session
Restrictive permissions reduce the chance of another local process replaying the same authenticated session.
$ wget --load-cookies custom-cookies.txt -qO- https://httpbin.org/cookies
{
"cookies": {
"auth_token": "A1B2C3D4E5",
"sessionid": "xyz123session"
}
}
Jar-based delivery is the better default for repeatable automation because wget applies the stored scope rules instead of sending every value to every host.
$ COOKIE_HEADER='sessionid=xyz123session; auth_token=A1B2C3D4E5'
$ wget --no-cookies --header="Cookie: $COOKIE_HEADER" -qO- https://httpbin.org/cookies
{
"cookies": {
"auth_token": "A1B2C3D4E5",
"sessionid": "xyz123session"
}
}
The raw header bypasses jar expiry and path matching, so keep it for narrow test cases rather than long-running scheduled jobs.
$ unset COOKIE_HEADER
$ wget --load-cookies custom-cookies.txt -qO- https://httpbin.org/cookies | grep --fixed-strings '"sessionid": "xyz123session"'
"sessionid": "xyz123session"
Check for account-specific data, expected JSON keys, or the normal page title so a login redirect is not mistaken for success.
$ rm -f custom-cookies.txt
Deleting the jar after use keeps reusable session material from lingering on disk longer than necessary.