redis-cli warns that a password on the command line may not be safe
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.Short answer
redis-cli prints this warning because a password given as -a or inside a -u URI appears in the process list and in shell history. The documented safer route is the REDISCLI_AUTH environment variable; --askpass prompts for the password instead. The --no-auth-warning flag only hides the message, it fixes nothing.
Fix it fast
1Find out which cause you have
Find which form of the password you are passing. The warning appears for both -a and a URI with a password.
history | grep -E 'redis-cli.*( -a | -u )'2Match what you see, then jump to its fix
What does the error look like?
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Cause 1 of 3
The password is passed with -a
1Check
-a takes the password as an argument. The Redis docs recommend the REDISCLI_AUTH environment variable instead, and say that -a wins when both are set.
ps -eo args | grep '[r]edis-cli'2Fix
Put the password in the environment for that command only, or let redis-cli ask for it.
# read it without echo, then run the command
read -rs REDISCLI_AUTH && export REDISCLI_AUTH
redis-cli PING
# or be prompted by redis-cli itself
redis-cli --askpass PING3Verify
The command answers PONG and prints no warning.
redis-cli PINGConfirmed by redis.io
Cause 2 of 3
The password sits inside a -u URI
1Check
The URI form redis://user:password@host:port/dbnum carries the password in the argument too, so it triggers the same warning.
echo "$REDIS_URL" | sed 's#//[^@]*@#//***@#'2Fix
Split the URI: give the host and port as options and keep the password in REDISCLI_AUTH. This form signs in as the default user.
export REDISCLI_AUTH='...'
redis-cli -h redis.example.com -p 6379 PING3Verify
The reply comes back without the warning.
redis-cli -h redis.example.com -p 6379 PINGConfirmed by redis.io
Cause 3 of 3
A script only needs the message gone
1Check
There is an option to silence the message. It does not hide the password from the process list.
redis-cli --help | grep -- '--no-auth-warning'2Fix
Only use the option where the process list is not shared, for example inside a private container.
redis-cli --no-auth-warning -a "$REDIS_PASSWORD" PING3Verify
No warning is printed.
redis-cli --no-auth-warning -a "$REDIS_PASSWORD" PINGConfirmed by redis.io
How do I stop it coming back?
- Keep the password in a secret store or an environment file with tight permissions, not in scripts.
- Set REDISCLI_AUTH from the secret store at the start of the job.
- Avoid pasting commands with passwords into shared terminals or tickets.
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?
Projects of mine built on the same technologies:
Related fixes
Security
Laravel answers a form or AJAX call with 419 Page Expired
419 Page Expired (a POST, PUT, PATCH or DELETE request)
Laravel could not match the CSRF token in your request to the one stored in the visitor's session.
5 causes, each with a fixSecurity
Redis logs a possible security attack from POST or Host commands
Possible SECURITY ATTACK detected. It looks like somebody is sending POST or Host: commands to Redis.
Redis writes this warning when a client sends text that looks like an HTTP request (POST or Host:) to its port.
3 causes, each with a fixSecurity
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fixSecurity
An [Authorize] endpoint rejects a request with a bearer token
Authorization Header sent: no Bearer token sent.
An [Authorize] endpoint without a policy name requires an authenticated user.
4 causes, each with a fixSecurity
ASP.NET Core API rejects an Angular user's token: the signature key was not found
401 Unauthorized
The API looked for the key named by the token's kid in the key set it downloaded from your Authority, and the key was not there.
4 causes, each with a fix