Home >Operation and Maintenance >Linux Operation and Maintenance >How to set redis access password under Linux (code)
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.
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
You can see our The service address of 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 fileredis.conf
> find /usr/local/redis/ -name redis.conf /usr/local/redis/etc/redis.conf
Modify the configuration file:
vim redis.conf
Just change the configuration file:
# requirepass foobared requirepass 123 指定密码123
The last step is to reload the configuration file:
redis-server /usr/local/redis/etc/redis.conf
Pass password -a
Access:
> redis-cli -h 192.168.17.105 -p 6379 -a 123
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
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!