centos下redis安全相关

博文背景:

由于发现众多同学,在使用云服务器时,安装的redis3.0+版本都关闭了protected-mode,因而都遭遇了挖矿病毒的攻击,使得服务器99%的占用率!!

因此我们在使用redis时候,最好更改默认端口,并且使用redis密码登录。

(1)redis没有用户概念,redis只有密码

(2)redis默认在工作在保护模式下。不允许远程任何用户登录的(protected-mode)

redis.conf设置

protected-mode yes   #打开保护模式
port 6380  #更改默认启动端口
requirepass xxxxxx   #设置redis启动密码,xxxx是自定义的密码

启动redis服务端

redis-server /opt/redis-4.0.10/redis.conf &     #指定配置文件启动redis,且后台启动

使用密码登录redis,使用6380端口

方法1,使用这个

[root@oldboy_python ~ 09:48:41]#redis-cli -p 6380
127.0.0.1:6380> auth xxxx
OK

方法2,此方案不安全,容易暴露密码

[root@oldboy_python ~ 09:49:46]#redis-cli -p 6380 -a xxxx
Warning: Using a password with '-a' option on the command line interface may not be safe.
127.0.0.1:6380> ping
PONG

补充

检查redis是否设置了密码

127.0.0.1:6380> CONFIG get requirepass

1) "requirepass"

2) "xxxxxx"

如果没有,也可以给redis设置密码(命令方式)

CONFIG set requirepass "xxxxxx"

因此你的redis就不容易被黑客入侵了。

我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1a36zff5cc86l

努力成为一个开发者 个人站点:www.pythonav.cn

由于发现众多同学,在使用云服务器时,安装的redis3.0+版本都关闭了protected-mode,因而都遭遇了挖矿病毒的攻击,使得服务器99%的占用率!!

因此我们在使用redis时候,最好更改默认端口,并且使用redis密码登录。

(1)redis没有用户概念,redis只有密码

(2)redis默认在工作在保护模式下。不允许远程任何用户登录的(protected-mode)

redis.conf设置

protected-mode yes   #打开保护模式
port 6380  #更改默认启动端口
requirepass xxxxxx   #设置redis启动密码,xxxx是自定义的密码

启动redis服务端

redis-server /opt/redis-4.0.10/redis.conf &     #指定配置文件启动redis,且后台启动

使用密码登录redis,使用6380端口

方法1,使用这个

[root@oldboy_python ~ 09:48:41]#redis-cli -p 6380
127.0.0.1:6380> auth xxxx
OK

方法2,此方案不安全,容易暴露密码

[root@oldboy_python ~ 09:49:46]#redis-cli -p 6380 -a xxxx
Warning: Using a password with '-a' option on the command line interface may not be safe.
127.0.0.1:6380> ping
PONG

补充

检查redis是否设置了密码

127.0.0.1:6380> CONFIG get requirepass

1) "requirepass"

2) "xxxxxx"

如果没有,也可以给redis设置密码(命令方式)

CONFIG set requirepass "xxxxxx"

因此你的redis就不容易被黑客入侵了。

我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=1a36zff5cc86l