skip to Main Content

When no password is set, we can issue for instance;

>> redis-cli keys * 

or

>> redis-cli config set requirepass "aaaaaa"

However, after we have have issued the latter, the first no longer works and results in:

>> redis-cli keys *
  (error) NOAUTH Authentication required.  

We need to authenticate. Sure.

>> redis-cli AUTH aaaaaa
   OK
>> redis-cli keys *
   (error) NOAUTH Authentication required. 

How do we authenticate and then able to execute a command?

Is this not possible? Heredocs only?

I’ve tried:

>> redis-cli AUTH aaaaaa && config set requirepass "aaaaaa"

But did not work. Also semicolon after aaaaaa. Not work.

How?

4

Answers


  1. Chosen as BEST ANSWER

    This seems to work:

    redis-cli <<- 'EOF'
            AUTH aaaaaa
            config set requirepass aaaaaa
    EOF
    

  2. The AUTH commands only last for the duration of the tcp connection. Each new invocation of redis-cli creates a new connection, thus you have to authenticate at each invocation.

    It is possible to execute several redis commands on one invocation of redis-cli: they must be separated by n

    Thus this would work:

    echo -e 'AUTH aaaaaankeys *' | redis-cli  
    

    Note: The other answer also provides a way to pass arguments separated by n to redis-cli

    Login or Signup to reply.
  3. You can pass the -a argument for authenticating the redis-cli command like this:

    redis-cli -h 127.0.0.1 -p 6379 -a mypassword keys *
    
    Login or Signup to reply.
  4. The answer from @aureliar is great. I prefer to use environment variables and ( since Redis 6 ) the default user:

    ▶ echo -e "AUTH default ${REDIS_PASSWORD}nkeys *" | redis-cli
    OK
    1) "foo:superkey:13-June-2022"
    

    Using a user instead of a global password is much better as you can restrict the commands and keys of a user. More details here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search