Your destination for complete Tech news

How to set a password for Redis?

616 0
< 1 min read

To set a password for Redis, you will need to edit the Redis configuration file (usually called “redis.conf”). The configuration file is typically located in the Redis installation directory.

The first step is to locate the configuration file. To locate it, you can use the following command:

$ locate redis.conf

This command will return the path of the redis.conf file.

Once you’ve located the configuration file, you will need to open it in a text editor and uncomment the following line:

# requirepass foobared

Then, replace “foobared” with the desired password.

For example:

requirepass mysecretpassword

Save the changes to the configuration file and close the text editor.

The next step is to restart the Redis server for the changes to take effect.

$ systemctl restart redis


$ service redis restart

Once the Redis server has been restarted, you can use the “AUTH” command in redis-cli to authenticate with the Redis server by providing the password you set in the configuration file.

$ redis-cli> auth mysecretpassword

It’s important to note that after setting a password, all the clients trying to connect to Redis will have to use the auth command to authenticate before performing any operation, otherwise, they will get an error message.

It’s also important to note that you should protect the redis.conf file, so that unauthorized users can’t read or modify it.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.