以下是在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
),并測試禁用命令是否生效。參考來源: