redis配置密码认证,通过密码可以进行连接

需求说明:

  今天配置了一台redis服务器,想要也和其他的数据库一样配置用户名/密码的方式进行登录.

  查找了一下,没看到配置用户名的地方,就是有认证密码,所以就做了测试,在此进行记录.

操作过程:

1.开启redis的密码认证,打开redis.conf,找到以下的内容

[aiprd@redhat6 redis-4.0.2]$ grep "requirepass" redis.conf 
# If the master is password protected (using the "requirepass" configuration
# requirepass foobared

2.将requirepass前面的注释去掉,并且将foobard改成自己的密码

[aiprd@redhat6 redis-4.0.2]$ grep "requirepass" redis.conf 
# If the master is password protected (using the "requirepass" configuration
requirepass An4Z0EnM

备注:认证密码已经被修改.

3.重启redis server使得配置文件生效,而后登录到redis客户端,获取key信息

[aiprd@redhat6 redis-4.0.2]$ src/redis-cli 
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379>

说明:如果进行密码认证是不能获取其中的数据的.注意,这里有一个重启redis server的过程.

4.通过在redis客户端中使用auth <password>的方式获取redis中的数据

[aiprd@redhat6 redis-4.0.2]$ src/redis-cli 
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth An4Z0EnM             #在此输入auth加上密码之后,就能够获redis中的数据.
OK
127.0.0.1:6379> keys *
(empty list or set)

5.在命令行中,直接通过-a选项加上密码进行认证

[aiprd@redhat6 redis-4.0.2]$ src/redis-cli -a An4Z0EnM
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> 

小结:

  在redis中没有用户的概念,就是一个认证的密码,认证成功后获取其中的数据.

文档创建时间:2018年4月16日20:37:29

原文地址:https://www.cnblogs.com/chuanzhang053/p/8858409.html