Reputation: 22369
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?
Upvotes: 5
Views: 20388
Reputation: 2308
My use-case is Redis in a docker exec cli.
As I'm learning Redis I didn't wanted to AUTH all the time.
So for testing I'm resetting the need for a password.
echo 'AUTH redis\nCONFIG SET requirepass ""' | redis-cli
On a restart of the container the password is set again.
Upvotes: 0
Reputation: 1639
Assign your password to REDISCLI_AUTH
env var (and export it). The docs say:
NOTE: For security reasons, provide the password to redis-cli
automatically via the REDISCLI_AUTH environment variable.
Upvotes: 1
Reputation: 22369
This seems to work:
redis-cli <<- 'EOF'
AUTH aaaaaa
config set requirepass aaaaaa
EOF
Upvotes: 0
Reputation: 2043
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 *
Upvotes: 11
Reputation: 1614
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
Upvotes: 10