mysql配置SSL证书登录的实现

2022-05-15 0 321
目录
  • 前言
  • 一、Mysql 启用 SSL 配置
    • 1.1 检查是否开启 ssl
    • 1.2 设置用户是否使用 SSL 连接
    • 1.3 使用 SSL 登录
  • 二、总结

    前言

    国家等级保护三级安全要求,mysql 的 ssl 需要安全证书加密,这里需要研究一下,选几个账户演示下即可。mysql 的版本为 8.0.20

    一、Mysql 启用 SSL 配置

    1.1 检查是否开启 ssl

    mysql> show variables like '%ssl%';
    +--------------------+-----------------+
    | Variable_name      | Value           |
    +--------------------+-----------------+
    | have_openssl       | YES             |  
    | have_ssl           | YES             |  # 已开启ssl
    | mysqlx_ssl_ca      |                 |
    | mysqlx_ssl_capath  |                 |
    | mysqlx_ssl_cert    |                 |
    | mysqlx_ssl_cipher  |                 |
    | mysqlx_ssl_crl     |                 |
    | mysqlx_ssl_crlpath |                 |
    | mysqlx_ssl_key     |                 |
    | ssl_ca             | ca.pem          |
    | ssl_capath         |                 |
    | ssl_cert           | server-cert.pem |
    | ssl_cipher         |                 |
    | ssl_crl            |                 |
    | ssl_crlpath        |                 |
    | ssl_fips_mode      | OFF             |
    | ssl_key            | server-key.pem  |
    +--------------------+-----------------+
    17 rows in set (0.56 sec)
    

    1.2 设置用户是否使用 SSL 连接

    mysql> select ssl_type from user where user = 'dev_fqr' ;
    +----------+
    | ssl_type |
    +----------+
    |          |
    +----------+
    1 row in set (0.05 sec)
    

    默认用户是没有使用 SSL 登录的。
    我们可以强制这个管理用户使用 SSL 登录。

    alter user 'xxx'@'%' require ssl;
    取消ssl验证:
    alter user 'xxx'@'%' require none;
    

    更改后,该账户就无法登录了,查看状态变成下面这种

    mysql> select ssl_type from user where user = 'dev_fqr' ;
    +----------+
    | ssl_type |
    +----------+
    | ANY      |
    +----------+
    1 row in set (0.01 sec)
    

    测试登录,本机无法直接登录。

    [root@localhost data]# mysql -u dev_fqr -p
    Enter password: 
    ERROR 2026 (HY000): SSL connection error: SSL is required but the server doesn't support it
    

    远程客户端无法直接登录:

    mysql配置SSL证书登录的实现

    1.3 使用 SSL 登录

    要想通过 SSL 登录,就需要用到下面这几个证书,通过 client 证书 与 server 端进行校验通过才能登录成功。

    mysql配置SSL证书登录的实现

    1) 本机登录

    在 data 目录下的三个文件证书登录。

    [root@localhost data]# mysql -udev_fqr -pDev@fqr2021 --ssl-ca=ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 55
    Server version: 8.0.22 MySQL Community Server - GPL
    ​
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    ​
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    ​
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    ​
    You are enforcing ssl connection via unix socket. Please consider
    switching ssl off as it does not make connection via unix socket
    any more secure.
    mysql> 
    

    2)navicate 远程客户端登录

    把这三个证书下载下来

    mysql配置SSL证书登录的实现

    配置证书目录,即可远程访问:

    mysql配置SSL证书登录的实现

    二、总结

    因为测评的时候不会看 JDBC 里面的配置,所以 JDBC 就不改了,不然要改动的地方非常的多,具体演示的时候可以用提前准备两个账号,到时候用客户端连接即可。
    目前两台 mysql 的ssl 用户如下:

    mysql配置SSL证书登录的实现

    到此这篇关于mysql配置SSL证书登录的实现的文章就介绍到这了,更多相关mysql SSL证书登录内容请搜索NICE源码以前的文章或继续浏览下面的相关文章希望大家以后多多支持NICE源码! 

    免责声明:
    1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 不得使用于非法商业用途,不得违反国家法律。否则后果自负!

    2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
    如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
    如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。

    NICE源码网 MySql mysql配置SSL证书登录的实现 https://www.niceym.com/38836.html