Home  >  Article  >  Database  >  How to set redis access password under Linux

How to set redis access password under Linux

藏色散人
藏色散人forward
2020-05-24 13:27:291941browse

Today the server installed redis. For security, set the password to access redis-server.

Recommended: "redis tutorial"

1. Find the redis.conf file

Our server has installed redis, now check redis through the command Process:

[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

You can see that the service address of our redis-server is 192.168.17.105 and the port is 6379. When accessing externally, you need to specify the corresponding IP and port:

redis-cli -h 192.168.17.105 -p 6379

Search redis installation directory

> whereis redis
redis: /usr/local/redis

We can see that redis is installed in this directory, and then find the configuration file redis.conf

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

Modify the configuration file:

vim redis.conf

Change the configuration file That’s it:

# requirepass foobared
requirepass 123   指定密码123

The last step is to reload the configuration file:

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

2. Connection test

Access via password -a:

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

Running result:

[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

The above is the detailed content of How to set redis access password under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete