Redis the method of configuring authentication password _redis

Source: Internet
Author: User
Tags redis

1. Configure by configuration file
Yum Redis configuration files are typically installed in/etc/redis.conf, open the configuration file to find

 
 

Remove the comment before the line and change the password to the required password to save the file

 
 

Restart Redis

sudo service redis restart 
#或者 
sudo service redis stop 

This time try to login Redis, found can be boarded, but the implementation of the specific command is prompted to operate not allowed

Redis-cli-h 127.0.0.1-p 6379 
redis 127.0.0.1:6379> redis 127.0.0.1:6379> 
keys * 
(Error) ERR Operation not permitted 
Redis 127.0.0.1:6379> Select 1 
(Error) ERR operation not permitted 
Redis 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

Redis-cli-h 127.0.0.1-p 6379-a myredis 
redis 127.0.0.1:6379> keys * 
1) "MySet" 
2) "Mysortset" 
Redis 127.0.0.1:6379> Select 1 
ok 
redis 127.0.0.1:6379[1]> config get requirepass 
1) "Requirepass" 

2. Configure from the command line

Redis 127.0.0.1:6379[1]> config set requirepass my_redis 
OK 
redis 127.0.0.1:6379[1]> config get Requirepass 
1) "Requirepass" 

No reboot Redis
Using the old password that is configured in the first step in the configuration file Redis, you will find that the original password is no longer available and the operation is denied

Redis-cli-h 127.0.0.1-p 6379-a myredis 
redis 127.0.0.1:6379> config get requirepass 

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

Redis-cli-h 127.0.0.1-p 6379-a my_redis 
redis 127.0.0.1:6379> config get requirepass 
1) "Requirepass" 

Try restarting the Redis, using the newly configured password login Redis to perform the operation, discover the new password is invalid, Redis reuse the password in the configuration file

sudo service redis restart 
stopping redis-server:                   [OK] 
starting redis-server:                   [OK] 
redis-cli-h 1 27.0.0.1-p 6379-a my_redis 
redis 127.0.0.1:6379> config get requirepass 
(Error) ERR operation not permitted 
redis-cli-h 127.0.0.1-p 6379-a myredis 
redis 127.0.0.1:6379> config get requirepass 
1) "Requirepass " 

In addition to making a password through the-a parameter at logon, you can also log on without specifying a password and authenticate before performing the operation.

Redis-cli-h 127.0.0.1-p 6379 
redis 127.0.0.1:6379> config get requirepass 
(Error) ERR operation not permitted 
Redis 127.0.0.1:6379> Auth Myredis 
OK 
Redis 127.0.0.1:6379> config get requirepass 
1) "Requirepass" 

3.master configured with password, slave how to configure
If master is configured with a password, slave will also configure the corresponding password parameters, otherwise it will not be normal replication.
Find the following line in the slave configuration file, remove the comment, and modify the password

 
 
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.