The Redis default configuration does not require password authentication, which means that the connection can be used as long as the host and port of the connected Redis server are correct. This has some security problems, so you need to enable the Redis authentication password to increase the security of the Redis server.
1. Modify the configuration file
The Redis profile is on by default /etc/redis.conf
, and it finds the following line:
#requirepass foobared
Remove the previous comment and modify it to the desired password:
Requirepass MyPassword (where MyPassword is the password to set)
2. Restart Redis
If Redis is already configured as a service
service, it can be restarted in the following ways:
Service Redis Restart
If Redis is not configured as a service
service, it can be restarted in the following ways:
/USR/LOCAL/BIN/REDIS-CLI shutdown/usr/local/bin/redis-server/etc/redis.conf
3. Login Verification
After setting up the Redis authentication password, the client will need to -a
enter the authentication password using the parameter, but it can log on successfully without any operation permission. As follows:
$./redis-cli-h 127.0.0.1-p 6379127.0.0.1:6379> Keys * (Error) Noauth authentication required.
Login with password authentication and verify the operation permissions:
$./redis-cli-h 127.0.0.1-p 6379-a mypassword127.0.0.1:6379> config get requirepass1) "Requirepass" 2) "MyPassword"
See the output similar to the above, indicating that the Reids password Authentication configuration was successful.
In addition to logging in as above, use the -a
parameters to enter the login password. You can also do this without specifying it after the connection:
4. Configure password at command line client (before Redis restart)
redis.conf
This configuration requires you to restart Redis by configuring a password, as described earlier. You can also configure passwords through the command line client, which does not have to restart Redis. The configuration is as follows:
127.0.0.1:6379> config set Requirepass newpasswordok127.0.0.1:6379> config get requirepass1) "Requirepass" 2) " NewPassword "
Note : using the command line client to configure the password, the redis.conf
password in the configuration file will still be used after the Redis restart.
5. Use the authentication password in the Redis cluster
If the Redis server, the cluster is used. In addition to master
configuring passwords in, you need to slave
configure them in. slave
Locate the following line in the configuration file, remove the comment and modify the master
same password:
# Masterauth Master-password
Article turned from: http://itbilu.com/linux/management/Ey_r7mWR.html
Turn: Redis Login with authentication password