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
This seems to work:
The
AUTH
commands only last for the duration of the tcp connection. Each new invocation ofredis-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 byn
Thus this would work:
Note: The other answer also provides a way to pass arguments separated by
n
toredis-cli
You can pass the -a argument for authenticating the redis-cli command like this:
The answer from @aureliar is great. I prefer to use environment variables and ( since Redis 6 ) the
default
user: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.