Redis server by default is not password protected.
There are two ways to change password for redis server.
- using command line
- Directly modifying redis.conf file
Redis set or change password
First check Password is set or not using auth password
command
127.0.0.1:6379> auth password
(error) ERR Client sent AUTH, but no password is set
It looks like password is not set for Redis server.
Let’s see how to change the password in multiple ways
- using config set
With interactive cli, you can change the password using CONFIG SET
CONFIG SET requirepass "12345"
requirepass is an configuration parameter for changing the password. It is not required to have a downtime and changes the password at runtime. This will set the password for redis server for current access only. if we restart the server, changes are lost.
To save this changes and run below command
CONFIG REWRITE
It will works for next restart onwards
- using redis.conf file
redis.conf file contains security related configured uncommented as seen below
Change from
# requirepass foobared
to
# requirepass 123467
Save the file.
Now, Restart or stop and start server to reload changes.
Now, Redis server is password protected.
Any client wants to communicate with server, need provide -a password
option.
redis-cli -h 127.0.0.1 -p 6379 -a password