Redis Configuration Password Authentication

Source: Internet
Author: User

Redis Configuration Password

1. Configuring with configuration Files
The Yum-style installation of Redis profiles is typically in/etc/redis.conf, which opens the configuration file to find

?
1 #requirepass foobared

Remove the comment before the line, and change the password to the desired password, save the file

?
1 requirepass myRedis

Restart Redis

?
1234 sudo service redis restart#或者sudo service redis stopsudo redis-server /etc/redis.conf

This is the time to try to log in to Redis and find that it is possible to mount, but the specific command is prompt operation is not allowed

?
1234567 redis-cli -h 127.0.0.1 -p 6379redis 127.0.0.1:6379>redis 127.0.0.1:6379> keys *(error) ERR operation notpermittedredis 127.0.0.1:6379> select 1(error) ERR operation notpermittedredis 127.0.0.1:6379[1]>

Try to log in with a password and execute a specific command to see that it can be executed successfully

?
123456789 redis-cli -h 127.0.0.1 -p 6379 -a myRedisredis 127.0.0.1:6379> keys *1) "myset"2) "mysortset"redis 127.0.0.1:6379> select1OKredis 127.0.0.1:6379[1]> config get requirepass1) "requirepass"2) "myRedis"


2. Configure through the command line

?
12345 redis 127.0.0.1:6379[1]> config setrequirepass my_redisOKredis 127.0.0.1:6379[1]> config get requirepass1) "requirepass"2) "my_redis"

No need to restart Redis
Using the old password configured in the configuration file in the first step to sign in to Redis, you will find that the original password is not available and the operation is rejected

?
123 redis-cli -h 127.0.0.1 -p 6379 -a myRedisredis 127.0.0.1:6379> config get requirepass(error) ERR operation notpermitted

Log in to Redis with the modified password to perform the appropriate action

?
1234 redis-cli -h 127.0.0.1 -p 6379 -a my_redisredis 127.0.0.1:6379> config get requirepass1) "requirepass"2) "my_redis

Try to restart Redis, log in to Redis with the newly configured password, discover that the new password is invalid, and Redis re-uses the password in the configuration file

?
12345678910 sudo service redis restartStopping redis-server:                                     [  OK  ]Starting redis-server:                                     [  OK  ]redis-cli -h 127.0.0.1 -p 6379 -a my_redisredis 127.0.0.1:6379> config get requirepass(error) ERR operation not permittedredis-cli -h 127.0.0.1 -p 6379 -a myRedisredis 127.0.0.1:6379> config get requirepass1) "requirepass"2) "myRedis"


In addition to setting a password with the-a parameter at login, you can log in without specifying a password and authenticate before performing the operation.

?
12345678 redis-cli -h 127.0.0.1 -p 6379redis 127.0.0.1:6379> config get requirepass(error) ERR operation notpermittedredis 127.0.0.1:6379> auth myRedisOKredis 127.0.0.1:6379> config get requirepass1) "requirepass"2) "myRedis"


3.master configured the password, slave how to configure

If master is configured with a password, slave must also configure the appropriate password parameters otherwise it will not be able to replicate normally.
Locate the following line in the config file in slave, remove the comment, and change the password

?
1 #masterauth  mstpassword

Redis Configuration Password Authentication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.