3112213 发表于 2015-11-13 09:34:23

redis的安全认证

redis端口对外开放并且没有配置认证选项,未授权用户可直接获取数据库中所有信息,造成严重的信息泄露。

安全的设置由两种方法:
方法一:
可以修改绑定的IP、端口和指定访问者IP
具体根据实际情况来设定,也可以直接在服务器防火墙上做设置。

方法二:
设置访问密码
在 redis.conf 中找到“requirepass”字段,取消注释并在后面填上你需要的密码。
注:修改redis的配置需要重启redis才能生效。

下面更具第二中方法进行设置

1
2
3
4
5
cd /opt/redis
cp redis.conf redis.conf.$(date +%F).bak
grep "requirepass" redis.conf
echo "requirepass lvniankeji" >> redis.conf
grep "requirepass" redis.conf






1
2
3
4
5
6
7
8
关闭服务
redis-cli shutdown
##带有密码的redis关闭
redis-cli -a lvniankeji shutdown
如果非默认端口,可指定端口:
redis-cli -p 6379shutdown
启动命令
redis-server conf/redis.conf





重启:

1
2
3
4
redis-cli -p 6379 -a lvniankeji shutdown
netstat -lntup | grep redis
/application/redis/bin/redis-server /application/redis/conf/redis.conf
netstat -lntup | grep redis






认证方式1

1
2
3
4
5
6
7
8
9
10
# redis-cli
127.0.0.1:6379> SEt gao deng
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth lvniankeji
OK
127.0.0.1:6379> SEt gao deng
OK
127.0.0.1:6379> get gao
"deng"
127.0.0.1:6379>





认证方式2

1
2
3
4
5
6
# redis-cli-a lvniankeji
127.0.0.1:6379> set gao a
OK
127.0.0.1:6379> get gao
"a"
127.0.0.1:6379>







###redis绑定IP
1.比较安全的办法是采用绑定IP的方式来进行控制。

1
bind 127.0.0.1




表示仅仅允许通过127.0.0.1这个ip地址进行访问。那么其实只有自己才能访问自己了,其他机器都无法访问他。


###redis权限方式,
##第一个是屏蔽set 命令;第二个是把get命令改为ggg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#rename-command set ""
echo 'rename-command set ""' >> redis.conf
echo 'rename-command get ggg' >> redis.conf
#####重启才能生效
# redis-cli
127.0.0.1:6379> set oo oo
(error) ERR unknown command 'set'
127.0.0.1:6379>
127.0.0.1:6379> get 01
(error) ERR unknown command 'get'
127.0.0.1:6379> ggg 01
(error) NOAUTH Authentication required.
127.0.0.1:6379> ggg id01
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth lvniankeji
OK
127.0.0.1:6379> ggg id01
"xiaogao"
127.0.0.1:6379>





屏蔽某个命令,也可以将某个命令改名


页: [1]
查看完整版本: redis的安全认证