Linux下设置redis访问密码

今天服务器安装了redis,为了安全设置一下访问redis-server的密码。

1、查找redis.conf文件

咱们服务器已经安装了redis,如今经过命令查看下redis的进程:redis

[root@lnp ~]# ps -aux|grep redis
root      7374  0.0  0.0 145312  7524 ?        Ssl  16:37   0:00 redis-server 192.168.17.105:6379
root     10692  0.0  0.0 112724   984 pts/7    S+   16:54   0:00 grep --color=auto redis

能够看到咱们的redis-server的服务地址为192.168.17.105,端口为6379,对外访问的时候须要指定对应的IP和端口:vim

redis-cli -h 192.168.17.105 -p 6379

查找redis安装目录安全

> whereis redis
redis: /usr/local/redis

咱们能够看到redis在该目录下安装,而后找到配置文件redis.conf服务器

> find /usr/local/redis/ -name redis.conf
/usr/local/redis/etc/redis.conf

修改配置文件:测试

vim redis.conf

改该配置文件便可:ui

# requirepass foobared
requirepass 123   指定密码123

最后一步,从新加载配置文件便可:code

redis-server /usr/local/redis/etc/redis.conf

2、链接测试

经过密码-a访问:server

> redis-cli -h 192.168.17.105 -p 6379 -a 123

运行结果:进程

[root@lnp etc]# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit

[root@lnp etc]# redis-cli -h 192.168.17.105 -p 6379
192.168.17.105:6379> keys *
(error) NOAUTH Authentication required.
192.168.17.105:6379> exit
[root@lnp etc]# redis-cli -h 192.168.17.105 -p 6379 -a 123
Warning: Using a password with '-a' option on the command line interface may not be safe.
192.168.17.105:6379> keys *
(empty list or set)
192.168.17.105:6379> exit
相关文章
相关标签/搜索