Currently, Redis does not have a configured password. Generally speaking, it has been regarded as a loophole and problem by many security detection systems. The official Redis turns off passwords by default. If you need to set a password, the current application scenarios can be divided into three types, as follows: :
1. Based on configuration files
requirepass
Set a password for redis by modifying in the redis.conf configuration file . After the configuration is completed, you need to restart it to take effect.
If you do not have the default redis.conf configuration file locally, you can download a corresponding version of the default configuration file from the official website and modify it.
Example:
requirepass 123456789
An example of starting redis with a configuration file is as follows:
./redis-server /etc/redis/redis.conf
2. Based on docker container
If redis is started based on a container, it can be set by adding container startup parameters. Examples of modifying the port and setting the password are as follows:
docker run -itd --name redis-demo -p 16379:6379 redis:latest --requirepass 123456789
3. Set via cli command line
The above two methods require restarting the service. If certain environmental requirements do not allow redis to be stopped, we can redis-cli
set it through the command line. The command example is as follows:
# 查看现有的redis密码:
config get requirepass
# 设置redis密码
config set requirepass 密码
If redis is a docker container, you can use the command docker exec -it 容器名称或ID bash
to enter the container and then enter redis-cli
to connect to the redis client command line.
Or directly use the redis desktop client tool to connect to redis and enter the client command line.
Note: After setting the password through the command, in order to prevent the next time the service restarts without a password, please pay attention to the above two methods 1 and 2 to configure the corresponding password after the service restarts.
(END)