加强redis安全

加强redis安全可从以下方面切入

 1. 使用非root用户启动redis

 2. 给redis设置密码

 3.绑定本地通信

 4.禁用敏感命令


首先查看redis

可知该redis是通过root用户运行的

添加redis用户


redis-cli -h 127.0.0.1

#进入redis通信

set name ciel

#如果显示ok则不需要密码,如果error,报错,没权限,则已设置密码


#在redis.conf设置密码

#requirepass footbar

找到requirepass 去掉#号,并设置一个复杂的密码

#查找bind,去掉#号

#bind 127.0.0.1   

#查找rename-command,设置如下

rename-command CONFIG ""

rename-command flushall ""

rename-command flushdb ""


用redis用户启动redis-server


setsid sudo -u redis /usr/bin/redis-server  /etc/redis.conf 


OK



以下是一个简单的 Linux Redis 安全检查脚本,它可以帮助你检查 Redis安全设置,以确保你的 Redis 服务器不会受到攻击: ```bash #!/bin/bash REDIS_CLI=`which redis-cli` # Check Redis version redis_version=`$REDIS_CLI info server | grep -oP "redis_version:\K[0-9]+\.[0-9]+\.[0-9]+"` echo "Redis version: $redis_version" # Check if Redis is running as root redis_user=`ps -ef | grep redis-server | grep -v grep | awk '{print $1}'` if [[ "$redis_user" = "root" ]]; then echo "Warning: Redis is running as root." fi # Check if Redis is password-protected redis_password=`$REDIS_CLI config get requirepass | tail -n 1` if [[ "$redis_password" = "\"\"" ]]; then echo "Warning: Redis is not password-protected." fi # Check if Redis is configured to bind to a specific IP address redis_bind=`$REDIS_CLI config get bind | tail -n 1` if [[ "$redis_bind" = "\"127.0.0.1\"" ]]; then echo "Warning: Redis is only listening on the loopback interface (127.0.0.1)." fi # Check if Redis is configured to allow remote connections redis_disable_remote=`$REDIS_CLI config get protected-mode | tail -n 1` if [[ "$redis_disable_remote" = "yes" ]]; then echo "Warning: Redis is configured to disable remote connections." fi # Check if Redis is configured to have keys with an expiration time redis_expire=`$REDIS_CLI config get noeviction | tail -n 1` if [[ "$redis_expire" = "no" ]]; then echo "Warning: Redis is configured to allow keys to never expire." fi ``` 使用方法: 1. 将上面的脚本保存为一个文件,例如 `redis_security_check.sh`。 2. 将脚本文件复制到 Redis 服务器上。 3. 执行以下命令使脚本文件可执行: ```bash chmod +x redis_security_check.sh ``` 4. 运行脚本: ```bash ./redis_security_check.sh ``` 脚本将输出 Redis 的版本号以及可能存在的安全问题。根据输出,你可以采取适当的措施来加强 Redis 服务器的安全性
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值