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
- #requirepass foobared
Remove the comment before the line, and change the password to the desired password, save the file
- Requirepass Myredis
Restart Redis
- sudo service Redis restart
- #或者
- sudo service Redis stop
- sudo 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
- 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) "Myredis"
2. Configure through 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"
- 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
- Redis-cli-h 127.0.0.1-p 6379-a Myredis
- Redis 127.0.0.1:6379> config Get requirepass
- (Error) ERR Operation not permitted
Log in to 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"
- 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
- sudo service Redis restart
- stopping redis-server: [OK]
- Starting redis-server: [OK]
- Redis-cli-h 127.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"
- 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.
- 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"
- 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
- #masterauth Mstpassword
Redis Configuration Authentication Password