Redis server by default is not password protected.
There are two ways to change the password for the redis server.
- using command line
- Directly modifying redis.conf file
Redis set or change password
First check Password is set or not using the
auth password command
127.0.0.1:6379> auth password (error) ERR Client sent AUTH, but no password is set
It looks like the password is not set for the 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 a 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 the redis server for current access only. if we restart the server, changes are lost.
To save these changes and run the below command
It will work for the next restart onwards
- using redis.conf file
Redis.conf file contains security related configured uncommented as seen below
# requirepass foobared
# requirepass 123467
Save the file.
Now, Restart or stop and start the server to reload changes.
Now, the Redis server is password protected.
Any client who wants to communicate with the server needs to provide the
-a password option.
redis-cli -h 127.0.0.1 -p 6379 -a password