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?
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 aaaaaa\nkeys *' | redis-cli
Note: The other answer also provides a way to pass arguments separated by \n
to redis-cli