Home > Database > Redis > body text

How to set redis access password under Linux

藏色散人
Release: 2020-05-24 13:27:29
forward
2018 people have browsed it

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
Copy after login

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
Copy after login

Search redis installation directory

> whereis redis
redis: /usr/local/redis
Copy after login

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
Copy after login

Modify the configuration file:

vim redis.conf
Copy after login

Change the configuration file That’s it:

# requirepass foobared
requirepass 123   指定密码123
Copy after login

The last step is to reload the configuration file:

redis-server /usr/local/redis/etc/redis.conf
Copy after login

2. Connection test

Access via password -a:

> redis-cli -h 192.168.17.105 -p 6379 -a 123
Copy after login

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
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template