Coder Perfect

How do I set a Redis password?


I’m using predis as a client and dealing with redis on my local machine, therefore I don’t need to set up a password to connect to the server with my php client. However, because I’m transferring my app to a live server, I’ll need to put up a password to access my redis server.

I have a few inquiries:

Is this the best approach to add the password?

> $my_server = array('host'     => '','port'     =>
> 6379,'database' => 1,'password'=>password);

to halt redis server, however it doesn’t work on my live server because there’s no redis-server process in my /etc/init.d file.

Asked by Don Gorgon

Solution #1

To set the password, open the redis.conf file and look for this line.

# requirepass foobared

Then remove the comment and replace foobared with your password. Make sure your password is at least 32 characters long; as the config file says, it’s easy for an outside user to guess up to 150k passwords every second.

The syntax you’ve demonstrated for using predis to authenticate with your new password is correct. Simply include password as a connection parameter.

To shut down redis, look in your config file for the pidfile setting; it’ll most likely be there.

pidfile /var/run/

Run the following command from the command prompt:

cat /var/run/

That will give you the process id of the currently operating server, and you can then stop it with that pid:

kill 3832


I also wanted to mention that you could use the /etc/init.d/redis-server stop command on your live server. All of the files in /etc/init.d/ are shell scripts, so copy the redis-server script from your local server to the live server in the same directory, and then look at what it does with vi or whatever you want; you may need to change some paths and things, but it should be quite straightforward.

Answered by profitphp

Solution #2

On the client, you can also use the following command.

config set requirepass p@ss$12E45 p@ss$12E45 config set requirepass p@ss$12E45 config set requirepass

The command above will set the redis server password to p@ss$12E45.

Answered by Suhas Gaikwad

Solution #3


(error) ERR Client sent AUTH, but no password is set
redis> CONFIG SET requirepass "mypass"
redis> AUTH mypass

Answered by Flavio Troia

Solution #4

sudo nano /etc/redis/redis.conf 

Find and remove the # requirepass foobared comment, then restart the server.

Your password has now been foobared.

Answered by Saurabh Chandra Patel

Solution #5

using redis-cli:

root@server:~# redis-cli> CONFIG SET requirepass secret_password

This will set a temporary password (until redis or server restart)

test password:

root@server:~# redis-cli> AUTH secret_password

Answered by Hlod

Post is based on