以下是在Ubuntu上配置Redis安全设置的关键步骤:
/etc/redis/redis.conf
,找到 bind
行,修改为仅允许本地或特定IP访问(如 bind 127.0.0.1
),避免暴露在公网。redis.conf
中取消 # requirepass foobared
注释,替换为强密码(如 requirepass StrongPass123!
),重启Redis生效。redis.conf
的 SECURITY
部分,使用 rename-command
禁用高风险命令(如 FLUSHALL
、CONFIG
),例如:rename-command FLUSHALL ""
(完全禁用)或重命名为不易猜测的名称。sudo ufw allow from <允许的IP> to any port 6379
sudo ufw reload
protected-mode
设置为 yes
(默认值),无密码时仅允许本地连接。验证配置:
sudo systemctl restart redis-server
。redis-cli
连接时需先输入密码(AUTH yourpassword
),并测试禁用命令是否生效。参考来源: