redis set password, change password

1. Setting method:

Method 1: Set the password through the command (temporarily effective, and the password will become invalid after restarting the server).
Use redis-cli to connect to redis, and execute the following command:

config set requirepass 123456
执行完毕,无需重启,退出客户端,重新登录就需要输入密码了 

Method 2: Set the password through the configuration file redis.conf (permanent)
Open redis.conf with the vi editor

[root@localhost /]# vi /etc/redis.conf

输入/requirepass 找到requirepass关键字,后面跟的就是密码,默认是注释掉的,即不需要密码

# The requirepass is not compatable with aclfile option and the ACL LOAD

# command, these will cause requirepass to be ignored.

#

# requirepass foobared
# 

注释打开,后面修改为自己的密码

# The requirepass is not compatable with aclfile option and the ACL LOAD

# command, these will cause requirepass to be ignored.

#
 requirepass 123456
# wq保存退出,重启服务器即可

2. Connection method:

1. Enter the password when connecting:

[root@localhost bin]# ./redis-cli -a 123456

2. Connect first and then enter the password:

[root@localhost bin]# ./redis-cli
127.0.0.1:6379> auth 123456

3. Closing method:

[root@localhost bin]# ./redis-cli -a 123456 shutdown

Open after reboot:

[root@localhost etc]# cd /usr/local/bin
[root@localhost bin]# redis-server /etc/redis.conf 
[root@localhost bin]# ps -ef|grep redis
root       7650   7491  0 18:36 pts/1    00:00:00 /usr/local/bin/redis-cli
root      12277      1  0 19:53 ?        00:00:00 redis-server 127.0.0.1:6379
root      12295   7156  0 19:53 pts/0    00:00:00 grep --color=auto redis
[root@localhost bin]# redis-cli
127.0.0.1:6379> auth 123456
OK

Guess you like

Origin blog.csdn.net/weixin_40379712/article/details/130062952