在Linux系统下对MySQL进行安全设置是保护数据库免受未授权访问和攻击的重要步骤。以下是一个全面的安全设置指南:
示例配置(/etc/login.defs):
PASS_MAX_DAYS 90 # 密码有效期
PASS_MIN_DAYS 0 # 密码修改间隔
PASS_MIN_LEN 8 # 密码最小长度
PASS_WARN_AGE 7 # 密码到期前警告
示例配置(/etc/pam.d/system-auth):
password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= minlen=8 lcredit=-1 ucredit=-1 dcredit=-1 ocredit=-1 enforce_for_root
示例配置(/etc/pam.d/sshd):
auth required pam_tally2.so onerr=fail deny=3 unlock_time=1800 even_deny_root root_unlock_time=300
示例配置(/etc/profile):
TMOUT=1800
select user,host from mysql.user;
select user,password from mysql.user where user='';
select user,password from mysql.user where password='';
update user set user='xxxxx' where user='root';
show grants for '用户名'@'主机域';
grant 权限1 权限2 权限3... on 数据库名称.表名称 to '用户名'@'用户地址';
update user set host='localhost' where user='root';
update user set host='ip地址' where user='xxx';
[mysqld]
bind_address=127.0.0.1
skip_networking=1
示例配置(/etc/my.cnf):
[mysqld]
ssl-ca=/path/to/ca.pem
ssl-cert=/path/to/server-cert.pem
ssl-key=/path/to/server-key.pem
service auditd status
service rsyslog status
示例:
groupadd sysgroup
useradd -g sysgroup sys
passwd sys
mkdir /vartest
chown -R sys:sysgroup /vartest
chmod 741 /vartest
示例:
yum update mysql-server
示例配置(iptables):
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -j DROP
示例:
revoke all on *.* from 'username'@'host';
grant select on database.* to 'username'@'host';
通过以上步骤,可以显著提高Linux下MySQL数据库的安全性,保护数据免受未授权访问和潜在的安全威胁。