How to set redis access password under Linux (code)

不言
Release: 2018-09-12 17:26:49
Original
3540 people have browsed it

The content of this article is about how to set the redis access password (code) under Linux. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Redis was installed on the server today. For security reasons, set the password to access redis-server.

1. Find the redis.conf file

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

[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 ourThe service address of redis-serveris192.168.17.105, and the port is6379. 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 fileredis.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

Just change the configuration file:

# 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

Pass password-aAccess:

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

Run 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

Related recommendations:

Detailed explanation of how to set the access password for Redis under win7 version (picture)

redis access control, password setting

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

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!