MySQL数据库安全加固(环境还是用之前装的ubuntu进行测试,详见文章39http://t.csdnimg.cn/7tuY2)
web容器Apache安全加固
一、mysql安全加固
1.mysql身份鉴别
默认账号:数据库系统默认普通账号或测试账号需要关闭或者删除
默认管理员账号:默认的管理员账号或管理测试账号需要关闭或删除,高权限账号需要控制
口令策略:口令的长度、复杂度、账号权限等严格按照等保或公司要求来设置
登录失败处理:设置登录失败的次数、等待时间等提升口令的安全,防止爆破等攻击
练习1:添加/删除/查看用户练习
#1.登录
tedu@ubuntu:~$ mysql -uroot -proot
#2.查看所有数据库
mysql> show databases;
#3.设置当前数据库
mysql> use mysql;
#4.查看当前数据库所有表
mysql> show tables;
#5.查看表中有哪些列
mysql> desc user;
#6.获取用户信息
mysql> select host,user from mysql.user;
#7.创建用户
mysql> create user testuser identified by '123456';
#8.创建用户
mysql> create user 'testuser2'@'localhost' identified by '123456';
#9.查看
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | testuser |
| localhost | debian-sys-maint |
| localhost | dvwa |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
| localhost | testuser2 |
+-----------+------------------+
#10.删除账号
mysql> drop user testuser;
mysql> drop user 'testuser2'@'localhost';
#11.重新查看
mysql> select host,user from mysql.user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | debian-sys-maint |
| localhost | dvwa |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
记录的是客户端的IP地址
默认是本地连接
练习2:mysql修改MySQL的root用户的密码,修改MySQL的root用户名
#1.通过alter user命令修改用户密码
tedu@ubuntu:~$ mysql -uroot -proot
mysql> alter user root@localhost identified by '123456';
mysql> exit;
#2.通过基本的数据操作update修改表中的数据方式修改用户名
tedu@ubuntu:~$ mysql -uroot -p123456;
mysql> select host,user from mysql.user;
mysql> update mysql.user set user='myroot' where user='root';
mysql> select host,user from mysql.user;
mysql> exit;
tedu@ubuntu:~$ service mysql restart
tedu@ubuntu:~$ mysql -umyroot -p123456
一定要注意:修改了用户名后,需要重启mysql(练习2的目的就是为了防爆破,不改用户名默认的就是在黑客的爆破字典中)
练习3:mysql用户及用户权限综合练习
可以切换到刚装好dvwa时的镜像,或者自己改登录信息
#1.root用户登录mysql
tedu@ubuntu:~$ mysql -uroot -proot
#2.查看所有用户
mysql> select host,user from mysql.user;
#3.查看dvwa用户权限
mysql> show grants for 'dvwa'@'localhost';
# USAGE 权限表示可以连接到数据库服务器
# 第二行表示对dvwa数据库有所有权限
+--------------------------------------------------------+
| Grants for dvwa@localhost |
+--------------------------------------------------------+
| GRANT USAGE ON *.* TO 'dvwa'@'localhost' |
| GRANT ALL PRIVILEGES ON `dvwa`.* TO 'dvwa'@'localhost' |
+--------------------------------------------------------+
#4.查看root用户权限
mysql> show grants for 'root'@'localhost';
# 第一行表示root拥有对所有数据库的所有权限
# 第二行是代理权限,可以不用关注
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
#5.创建用户
mysql> create user testuser identified by '123456';
#6.查看所有用户
mysql> select host,user from mysql.user;
# % 表示通过该用户可以任意远程连接但是需要配置文件的配合,默认配置不支持远程。
# localhost表示通过该用户只能本地连接
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | testuser |
| localhost | debian-sys-maint |
| localhost | dvwa |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
#7.查看testuser用户的权限,注意与其他用户的区别
mysql> show grants for testuser;
# 只有连接权限
+--------------------------------------+
| Grants for testuser@% |
+--------------------------------------+
| GRANT USAGE ON *.* TO 'testuser'@'%' |
+--------------------------------------+
#8.退出,尝试使用testuser用户连接
mysql>exit;
tedu@ubuntu:~$ mysql -u