You've successfully subscribed to StackInk
Great! Next, complete checkout for full access to StackInk
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

How to set password for Redis Server ?

We can make Redis servers password protected in two ways, by directly setting it on the redis config file or via the Redis command line interface.
We use the AUTH comment to authenticate the password of an Redis protected server. And once the password given matches with the previously set password then, we will get an OK status code as response from the server, other wise the redis server will response an ERR invalid password error.

Basic AUTH command

AUTH Password

Setup Password using Terminal.

Step 1 :
Open Terminal and connect to the Redis command line interface


redis-cli

##or if a different host or same host with a binded Ip Address

redis-cli -h <IPADDRESS>

Step 2 :

Let’s check if the Redis Server already got a password or not.


AUTH mypassword

#Response
  
  #If Password is not set then server replies
  (error) ERR Client sent AUTH, but no password is set
  
  #Else if Incorrect
  (error) ERR invalid password
  
  

Step 3 :


# Set a Password

CONFIG SET requirepass "mypassword"

# Server Response will be

OK

Step 4 :


# Authenticate the password
AUTH "mypassword"

# If Password Matches then Server Response will be

OK

# Else if Incorrect
(error) ERR invalid password

Setup Password using redis config file.

Step 1 :


#Open the redis config file using nano.

sudo nano /etc/redis/redis.conf

Step 2 :

Find the line starts with requirepass, Uncomment the line and set a new password


# requirepass yourpassword

-to-

requirepass mypassword

Step 3 :


Save the File and restart the Redis-Server.
Use the AUTH Comment to test the password.