1 OpenSSH

OpenSSH 是 SSH (Secure SHell) 协议的免费开源实现。

OpenSSH是使用SSH透过计算机网络加密通讯的实现。

SSH协议族可以用来进行远程控制, 或在计算机之间传送文件。

而实现此功能的传统方式,如 telnet(终端仿真协议)、 rcp ftp、 rlogin、rsh都是极为不安全的,并且会使用明文传送密码。

OpenSSH提供了服务端后台程序和客户端工具,用来加密远程控制和文件传输过程中的数据,并由此来代替原来的类似服务。

1-1 定义

OpenSSH在其官网是如此描述的:

OpenSSH is the premier connectivity tool for remote login with the SSH protocol. It encrypts all traffic to eliminate eavesdropping, connection hijacking, and other attacks. In addition, OpenSSH provides a large suite of secure tunneling capabilities, several authentication methods, and sophisticated configuration options.

  1. OpenSSH是使用SSH协议进行远程登录的主要连接工具。
  2. 它对所有流量进行加密,以消除窃听、连接劫持和其他攻击。
  3. 此外,OpenSSH还提供了一整套安全的隧道功能、几种身份验证方法和复杂的配置选项。

1-2 项目组件

截至目前(2020-10-15),OpenSSH的最新版本为: OpenSSH 8.4,其发布于 2020.9.27

The OpenSSH suite consists of the following tools:

  • Remote operations are done using ssh, scp, and sftp.
  • Key management with ssh-add, ssh-keysign, ssh-keyscan, and ssh-keygen.
  • The service side consists of sshd, sftp-server, and ssh-agent.
  1. OpenSSH套件由以下工具组成:
  2. + 远程操作是使用sshscpsftp完成的。
  3. + 使用ssh-addssh-keysignssh- keyyscanssh-keygen进行密钥管理。
  4. + 服务端由sshdsftp-serverssh-agent组成。
  • 客户端: ssh / scp / sftp

    SSH: SSH客户端。rlogin与Telnet的替代方案。

    SCP/SFTP: rcp的替代方案,将文件复制到其他电脑上。
  • 服务端: sshd / sftp-server / ssh-agent

    SSH服务端
  • 密钥管理: ssh-add / ssh-keysign / ssh-keyscan / ssh-keygen

    ssh-add/ssh-agent: 帮助用户不需要每次都要输入密钥密码的工具。

    ssh-keysign:

    ssh-keyscan: 扫描一群机器,并记录其公钥。

    ssh-keygen: 产生RSA或DSA密钥,用来认证用。

1-3 风险与漏洞

  1. OpenSSH 3.6.1p2及更早版本中,
  2. 当禁用PermitRootLogin并使用PAM键盘交互式身份验证时,sshd在使用正确密码进行root登录尝试后不会插入延迟,
  3. 这使远程攻击者更容易使用时序差异来确定是否多步验证的密码步骤是成功的,与CVE-2003-0190不同。

CVE-2003-0190 - CVE

CNNVD-200305-021 - 中国国家信息安全漏洞库

[风险描述]

  1. OpenSSH是一种开放源码的SSH协议的实现,目前移植在多种系统下工作。
  2. 移植的OpenSSH版本在支持PAM的情况下存在时序攻击问题,远程攻击者可以利用这个漏洞判断用户是否存在,导致信息泄露。
  3. 根据测试,如果OpenSSH以--with-pam进行配置的情况下,由于对合法用户和非法用户响应信息的时间不同,该可以判断系统用户是否存在。
  4. 在判断用户情况下,可以进一步通过猜测密码进行攻击。
  • SSH

Secure Shell(安全外壳协议,简称SSH)是一种加密的网络传输协议,可在不安全的网络中为网络服务提供安全的传输环境。SSH通过在网络中创建安全隧道来实现SSH客户端与服务器之间的连接。虽然任何网络服务都可以通过SSH实现安全传输,SSH最常见的用途是远程登录系统,人们通常利用SSH来传输命令行界面和远程执行命令。使用频率最高的场合类Unix系统,但是Windows操作系统也能有限度地使用SSH。2015年,微软宣布将在未来的操作系统中提供原生SSH协议支持。

在设计上,SSH是Telnet和非安全shell的替代品。Telnet和Berkeleyrlogin、rsh、rexec等协议采用明文传输,使用不可靠的密码,容易遭到监听、嗅探和中间人攻击。SSH旨在保证非安全网络环境(例如互联网)中信息加密完整可靠。

不过,SSH也被指出有被嗅探甚至解密的漏洞。

早在2011年,中国的互联网审查机构已经有能力针对SSH连接的刺探及干扰

而后爱德华·斯诺登泄露的文件也指出,美国国家安全局有时能够把SSH协议传输的信息解密出来,从而读出SSH会话的传输内容

2017年7月6日,非营利组织维基解密确认美国中央情报局已经开发出能够在Windows或Linux操作系统中窃取SSH会话的工具。

1-4 关于开源: OpenSSH————开源计划OpenBSD的子计划

OpenSSH is developed by a few developers of the OpenBSD Project and made available under a BSD-style license.

OpenSSH is incorporated into many commercial products, but very few of those companies assist OpenSSH with funding.

OpenBSD is developed entirely by volunteers. The project's development environment and developer events are funded through contributions collected by The OpenBSD Foundation. Contributions ensure that OpenBSD will remain a vibrant and free operating system.

Contributions towards OpenSSH can be sent to the OpenBSD Foundation.

  1. OpenSSH是由OpenBSD项目的一些开发人员开发的,并在bsd风格的许可下提供。
  2. OpenSSH被整合到许多商业产品中,但这些公司中很少有公司为OpenSSH提供资金支持。 [来自官方的吐槽...]
  3. OpenBSD完全由志愿者开发。
  4. 该项目的开发环境和开发人员活动由OpenBSD基金会收集的捐款提供资金。
  5. 贡献的资金确保了OpenBSD将继续是一个充满活力和自由的操作系统。
  6. OpenSSH的资金捐献可以发送到OpenBSD基金会。
  • 补充说明: OpenSSH 与 OpenSSL
  1. OpenSSH常常被误认以为与OpenSSL有关联,但实际上这两个计划的有不同的目的,不同的发展团队,名称相近。
  2. 只是因为两者有同样的软件发展目标──提供开放源代码的加密通讯软件。

2 常用命令

2-1 ssh / sshd

  1. # 开启/关闭 开机自启 【SSH服务端】
  2. systemctl enable/disable sshd
  3. # 重新加载【SSH服务端】服务配置
  4. systemctl reload sshd
  5. # 启动/停止/重启 【SSH服务端】服务
  6. systemctl start/stop/restart sshd
  7. /etc/init.d/sshd start/stop/restart
  8. # 查看【SSH服务端】服务状态( inactive(非活动状态) / active(活动状态) )
  9. systemctl status sshd
  10. /etc/init.d/sshd status
  11. systemctl list-unit-files | grep sshd netstat -antulp | grep ssh # 列出本机已开启服务当前状态

  1. [查看 OpenSSH 版本]
  2. [root@govern ~]# ssh -V
  3. OpenSSH_8.1p1, OpenSSL 1.0.1e-fips 11 Feb 2013
  4. [查看 OpenSSL 版本]
  5. [root@govern ~]# openssl version
  6. OpenSSL 1.0.1e-fips 11 Feb 2013

3 应用场景

场景1 - 在Git配置远程仓库(GitLab/Github)中的应用

  • step1 给Git 设置一个全局的账户(远程仓库GitLab[/Github/...]账户)
  1. git config user.name "yourGitLabName"
  2. git config user.email "myGitlab@email.cn"
  • step2 使用远程仓库GitLab账户的邮箱生成SSH密钥对

    (默认:在Windows系统中生成id_rsa :C:/用户/username/.ssh/id_rsa)
  1. ssh-keygen -t rsa -C "myGitlab@email.cn"

至此,SSH密钥对(公钥[*.pub]+私钥)已生成,在 ~/.ssh 文件夹下
(~/.ssh 即C: Users/yourUserName/)

> 文件1: id_rsa [私钥]
> 文件2: id_rsa.pub [公钥]

  • step3 将公钥文件的内容全文复制到 GitLab的个人账户的SSH公钥管理处

  • ...(本地电脑单远程仓库账户时,单即可直接使用Git了)

》》》 多远程仓库

但是Git 默认的只会用id_rsa这个密钥对。

如果想针对不同的域名(多远程仓库)使用不同的密钥对, 需要做设置,即 配置known_hosts文件。

  • step4 配置known_hosts文件

    PS1: 把id_rsa_github密钥对添加到配置列表。若此命令报错 ,请先执行:ssh-agent bash

    ssh-agent tcsh (另一Shell)
  1. ssh-add ~/.ssh/id_rsa_github

PS2:新增完后,可执行本命令进行测试:

  1. ssh -T git@github.com

PS3:在后续的使用中,例如git clonegit init/clone/pull/push等与远程仓库相关的首次操作前,建议先检查【git config –get user.email / git config -l / git branch -av】一下:

  • 本地仓库对应的个人账户是否无误
  • 本地仓库对应的远程仓库地址是否无误

    (避免将源码提交至错误的远程仓库 或 出现 push/pull失败等情况)

PS4:获取SSH公钥的HASH指纹值——ssh-keygen -lf ~/.ssh/id_rsa_github.pub

-l 表示"list",而不是创建新密钥; -f 表示"filename"

4 OpenSSL

4-1 OpenSSL 命令

4-1-1 openssl --help

  1. [root@centos7-202010061038 ~]# openssl --help
  2. openssl:Error: '--help' is an invalid command.
  3. Standard commands
  4. asn1parse ca ciphers cms
  5. crl crl2pkcs7 dgst dh
  6. dhparam dsa dsaparam ec
  7. ecparam enc engine errstr
  8. gendh gendsa genpkey genrsa
  9. nseq ocsp passwd pkcs12
  10. pkcs7 pkcs8 pkey pkeyparam
  11. pkeyutl prime rand req
  12. rsa rsautl s_client s_server
  13. s_time sess_id smime speed
  14. spkac ts verify version
  15. x509
  16. Message Digest commands (see the `dgst' command for more details)
  17. md2 md4 md5 rmd160
  18. sha sha1
  19. Cipher commands (see the `enc' command for more details)
  20. aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb
  21. aes-256-cbc aes-256-ecb base64 bf
  22. bf-cbc bf-cfb bf-ecb bf-ofb
  23. camellia-128-cbc camellia-128-ecb camellia-192-cbc camellia-192-ecb
  24. camellia-256-cbc camellia-256-ecb cast cast-cbc
  25. cast5-cbc cast5-cfb cast5-ecb cast5-ofb
  26. des des-cbc des-cfb des-ecb
  27. des-ede des-ede-cbc des-ede-cfb des-ede-ofb
  28. des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb
  29. des-ofb des3 desx idea
  30. idea-cbc idea-cfb idea-ecb idea-ofb
  31. rc2 rc2-40-cbc rc2-64-cbc rc2-cbc
  32. rc2-cfb rc2-ecb rc2-ofb rc4
  33. rc4-40 rc5 rc5-cbc rc5-cfb
  34. rc5-ecb rc5-ofb seed seed-cbc
  35. seed-cfb seed-ecb seed-ofb zlib
  • openssl命令总览
  1. version 用于查看版本信息
  2. enc 用于加解密
  3. ciphers 列出加密套件
  4. genrsa 用于生成私钥
  5. rsa RSA密钥管理(例如:从私钥中提取公钥)
  6. req 生成证书签名请求(CSR)
  7. crl 证书吊销列表(CRL)管理
  8. ca CA管理(例如对证书进行签名)
  9. dgst 生成信息摘要
  10. rsautl 用于完成RSA签名、验证、加密和解密功能
  11. passwd 生成散列密码
  12. rand 生成伪随机数
  13. speed 用于测试加解密速度
  14. s_client 通用的SSL/TLS客户端测试工具
  15. X509 X.509证书管理
  16. verify X.509证书验证
  17. pkcs7 PKCS#7协议数据管理
  18. pkcs8 PKCS#8协议数据管理
  19. pkcs12 PKCS#12协议数据管理

4-1-2 openssl ciphers

openssl ciphers [-v] [-ssl2] [-ssl3] [-tls1] [cipherlist]

  1. -v:详细列出所有加密套件。包括ssl版本(SSLv2SSLv3以及 TLS)、密钥交换算法、身份验证算法、对称算法、摘要算法以及该算法是否可以出口。
  2. -ssl2:只列出SSLv2使用的加密套件。
  3. -ssl3:只列出SSLv3使用的加密套件。
  4. -tls1:只列出tls使用的加密套件。
  5. cipherlist:列出一个cipher list的详细内容。用此项能列出所有符合规则的加密套件,如果不加-v选项,它只显示各个套件名字;
  • case1 查看是否支持某一 密钥套件(cipher suite)
  1. [root@centos7-202010061038 ~]# openssl ciphers | awk 'BEGIN{i=1}{gsub(/:/, ",\n");i++;print}' | grep -i DES
  2. ECDHE-RSA-DES-CBC3-SHA,
  3. ECDHE-ECDSA-DES-CBC3-SHA,
  4. EDH-RSA-DES-CBC3-SHA,
  5. EDH-DSS-DES-CBC3-SHA,
  6. DH-RSA-DES-CBC3-SHA,
  7. DH-DSS-DES-CBC3-SHA,
  8. ECDH-RSA-DES-CBC3-SHA,
  9. ECDH-ECDSA-DES-CBC3-SHA,
  10. DES-CBC3-SHA,
  11. PSK-3DES-EDE-CBC-SHA,
  12. KRB5-DES-CBC3-SHA,
  13. KRB5-DES-CBC3-MD5,

  1. [root@centos7 ~]# openssl ciphers -v | grep -i DES
  2. ECDHE-RSA-DES-CBC3-SHA SSLv3 Kx=ECDH Au=RSA Enc=3DES(168) Mac=SHA1
  3. ECDHE-ECDSA-DES-CBC3-SHA SSLv3 Kx=ECDH Au=ECDSA Enc=3DES(168) Mac=SHA1
  4. EDH-RSA-DES-CBC3-SHA SSLv3 Kx=DH Au=RSA Enc=3DES(168) Mac=SHA1
  5. EDH-DSS-DES-CBC3-SHA SSLv3 Kx=DH Au=DSS Enc=3DES(168) Mac=SHA1
  6. DH-RSA-DES-CBC3-SHA SSLv3 Kx=DH/RSA Au=DH Enc=3DES(168) Mac=SHA1
  7. DH-DSS-DES-CBC3-SHA SSLv3 Kx=DH/DSS Au=DH Enc=3DES(168) Mac=SHA1
  8. ECDH-RSA-DES-CBC3-SHA SSLv3 Kx=ECDH/RSA Au=ECDH Enc=3DES(168) Mac=SHA1
  9. ECDH-ECDSA-DES-CBC3-SHA SSLv3 Kx=ECDH/ECDSA Au=ECDH Enc=3DES(168) Mac=SHA1
  10. DES-CBC3-SHA SSLv3 Kx=RSA Au=RSA Enc=3DES(168) Mac=SHA1
  11. PSK-3DES-EDE-CBC-SHA SSLv3 Kx=PSK Au=PSK Enc=3DES(168) Mac=SHA1
  12. KRB5-DES-CBC3-SHA SSLv3 Kx=KRB5 Au=KRB5 Enc=3DES(168) Mac=SHA1
  13. KRB5-DES-CBC3-MD5 SSLv3 Kx=KRB5 Au=KRB5 Enc=3DES(168) Mac=MD5
  • case2 列出所有加密套件的详细信息

    -v:详细列出所有加密套件。包括ssl版本(SSLv2、SSLv3以及 TLS)、密钥交换算法、身份验证算法、对称算法、摘要算法以及该算法是否可以出口。
  1. [root@centos7 ~]# openssl ciphers -v
  2. ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD
  3. ECDHE-ECDSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(256) Mac=AEAD
  4. ECDHE-RSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA384
  5. ECDHE-ECDSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA384
  6. ECDHE-RSA-AES256-SHA SSLv3 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA1
  7. ECDHE-ECDSA-AES256-SHA SSLv3 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA1
  8. DH-DSS-AES256-GCM-SHA384 TLSv1.2 Kx=DH/DSS Au=DH Enc=AESGCM(256) Mac=AEAD
  9. DHE-DSS-AES256-GCM-SHA384 TLSv1.2 Kx=DH Au=DSS Enc=AESGCM(256) Mac=AEAD
  10. DH-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=DH/RSA Au=DH Enc=AESGCM(256) Mac=AEAD
  11. DHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=DH Au=RSA Enc=AESGCM(256) Mac=AEAD
  12. DHE-RSA-AES256-SHA256 TLSv1.2 Kx=DH Au=RSA Enc=AES(256) Mac=SHA256
  13. DHE-DSS-AES256-SHA256 TLSv1.2 Kx=DH Au=DSS Enc=AES(256) Mac=SHA256
  14. ...

4-1-3 openssl s_client

  • case1 openssl s_client --help
  1. [root@centos7-202010061038 ~]# openssl s_client --help
  2. unknown option --help
  3. usage: s_client args
  4. -host host - use -connect instead
  5. -port port - use -connect instead
  6. -connect host:port - who to connect to (default is localhost:4433)
  7. -verify_hostname host - check peer certificate matches "host"
  8. -verify_email email - check peer certificate matches "email"
  9. -verify_ip ipaddr - check peer certificate matches "ipaddr"
  10. -verify arg - turn on peer certificate verification
  11. -verify_return_error - return verification errors
  12. -cert arg - certificate file to use, PEM format assumed
  13. -certform arg - certificate format (PEM or DER) PEM default
  14. -key arg - Private key file to use, in cert file if
  15. not specified but cert file is.
  16. -keyform arg - key format (PEM or DER) PEM default
  17. -pass arg - private key file pass phrase source
  18. -CApath arg - PEM format directory of CA's
  19. -CAfile arg - PEM format file of CA's
  20. -trusted_first - Use trusted CA's first when building the trust chain
  21. -no_alt_chains - only ever use the first certificate chain found
  22. -reconnect - Drop and re-make the connection with the same Session-ID
  23. -pause - sleep(1) after each read(2) and write(2) system call
  24. -prexit - print session information even on connection failure
  25. -showcerts - show all certificates in the chain
  26. -debug - extra output
  27. -msg - Show protocol messages
  28. -nbio_test - more ssl protocol testing
  29. -state - print the 'ssl' states
  30. -nbio - Run with non-blocking IO
  31. -crlf - convert LF from terminal into CRLF
  32. -quiet - no s_client output
  33. -ign_eof - ignore input eof (default when -quiet)
  34. -no_ign_eof - don't ignore input eof
  35. -psk_identity arg - PSK identity
  36. -psk arg - PSK in hex (without 0x)
  37. -ssl3 - just use SSLv3
  38. -tls1_2 - just use TLSv1.2
  39. -tls1_1 - just use TLSv1.1
  40. -tls1 - just use TLSv1
  41. -dtls1 - just use DTLSv1
  42. -fallback_scsv - send TLS_FALLBACK_SCSV
  43. -mtu - set the link layer MTU
  44. -no_tls1_2/-no_tls1_1/-no_tls1/-no_ssl3/-no_ssl2 - turn off that protocol
  45. -bugs - Switch on all SSL implementation bug workarounds
  46. -cipher - preferred cipher to use, use the 'openssl ciphers'
  47. command to see what is available
  48. -starttls prot - use the STARTTLS command before starting TLS
  49. for those protocols that support it, where
  50. 'prot' defines which one to assume. Currently,
  51. only "smtp", "pop3", "imap", "ftp", "xmpp",
  52. "xmpp-server", "irc", "postgres", "lmtp", "nntp",
  53. "sieve" and "ldap" are supported.
  54. -xmpphost host - Host to use with "-starttls xmpp[-server]"
  55. -name host - Hostname to use for "-starttls lmtp" or "-starttls smtp"
  56. -krb5svc arg - Kerberos service name
  57. -engine id - Initialise and use the specified engine
  58. -rand file:file:...
  59. -sess_out arg - file to write SSL session to
  60. -sess_in arg - file to read SSL session from
  61. -servername host - Set TLS extension servername in ClientHello
  62. -tlsextdebug - hex dump of all TLS extensions received
  63. -status - request certificate status from server
  64. -no_ticket - disable use of RFC4507bis session tickets
  65. -serverinfo types - send empty ClientHello extensions (comma-separated numbers)
  66. -curves arg - Elliptic curves to advertise (colon-separated list)
  67. -sigalgs arg - Signature algorithms to support (colon-separated list)
  68. -client_sigalgs arg - Signature algorithms to support for client
  69. certificate authentication (colon-separated list)
  70. -nextprotoneg arg - enable NPN extension, considering named protocols supported (comma-separated list)
  71. -alpn arg - enable ALPN extension, considering named protocols supported (comma-separated list)
  72. -legacy_renegotiation - enable use of legacy renegotiation (dangerous)
  73. -use_srtp profiles - Offer SRTP key management with a colon-separated profile list
  74. -keymatexport label - Export keying material using label
  75. -keymatexportlen len - Export len bytes of keying material (default 20)
  • case2 验证服务端/指定主机是否支持指定的cipher
  1. # openssl s_client -connect www.baidu.com:443 -tls1_2 -cipher ECDHE-ECDSA-AES128-GCM-SHA256

-tls1_2 用于指定tls版本

4-2 SSL协议的实现组件 : OpenSSL / wolfSSL / yaSSL

1) OpenSSL | YaSSL(CYaSSL) := 原wolfSSL的早期(C++)版

2) 所支持的SSL/TLS/DTLS协议版本

  1. YaSSL / CYaSSL : SSL3.0 / TLS1.0 / TLS1.1 / DTLS1.0 【即 不支持:TLS1.2
  2. wolfSSL : SSL3.0 / TLSv1.0TLSv1.1TLSv1.2 / TLSv1.3
  3. openSSL : SSL3.0 / TLS1.0 / TLS1.1 / TLS1.2, TLS1.3

3) 支持的加密算法

  1. YaSSL - DES, 3DES, AES, ARC4, RABBIT, HC-128

4) 官网及特点

  1. yet another SSL / CYaSSLwolfSSL的早期版本,基于C++,为嵌入式环境和资源限制的实时操作系统提供SSL功能库
  2. 始建于2004,其github2014年已停止维护,但最新版2.4.42017年释出。
  3. wolfSSL / CyaSSL / yaSSL的第一个主要用户是MySQL
  4. 通过捆绑MySQLyaSSL已实现百万级的极高分发量;但MySQL5.7.28及以后,便不再支持yaSSL,且仅支持OpenSSL
  5. wolfSSL 北城百科 https://www.beichengjiu.com/cryptography/169285.html





  1. Wolfssl的定位:1)嵌入式TLS 2)原名:CYaSSL / yet another SSL
  2. https://segmentfault.com/a/1190000000471532
  3. https://bugs.mysql.com/bug.php?id=75239

4-3 MySQL对OpenSSL / yaSSL的支持

4-3-1 MySQL对OpenSSL / yaSSL的支持 (stop at 5.7.28)

  1. 2.9.6配置SSL库支持 - https://dev.mysql.com/doc/refman/5.7/en/source-ssl-library-configuration.html
  2. 仅在MySQL 5.7.28之前,才可以使用yaSSL替代OpenSSL来编译MySQL。从MySQL 5.7.28开始,对yaSSL的支持已删除,所有MySQL构建都使用OpenSSL
  3. 如果从源发行版编译MySQL,则CMake会将发行版 配置为默认使用已安装的OpenSSL库。
  4. 要确定服务器是使用OpenSSL还是yaSSL编译的,请检查是否存在仅适用于OpenSSL的任何系统变量或状态变量。请参见第6.3.4节“依赖于SSL库的功能”
  1. https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-11.html
  2. MySQL 8.0构建现在使用OpenSSL而不是yaSSL作为默认SSL库。MySQL不再支持使用yaSSL进行构建,并且源发行版不再包括yaSSL
  1. 6.3.4 SSL Library-Dependent Capabilities - https://dev.mysql.com/doc/refman/5.7/en/ssl-libraries.html
  2. OpenSSL支持TLSv1TLSv1.1TLSv1.2协议。yaSSL仅支持TLSv1TLSv1.1协议。

4-3-2 MySQL 5.7.28版本前后对SSL的默认开闭情况

【MySQL 5.7.27及以前,默认关闭SSL / MySQL 5.7.28及以后,默认开启(open)SSL】

详见此博文: 故障分析 | Bad handshake,升级 5.7.28 引起的“血案” - CSDN

  • [5.7.27]
  1. mysql> select @@version;
  2. +------------+
  3. | @@version |
  4. +------------+
  5. | 5.7.27-log |
  6. +------------+
  7. 1 row in set (0.00 sec)
  8. mysql> show variables like '%ssl%';
  9. +---------------+----------+
  10. | Variable_name | Value |
  11. +---------------+----------+
  12. | have_openssl | DISABLED |
  13. | have_ssl | DISABLED |
  14. | ssl_ca | |
  15. | ssl_capath | |
  16. | ssl_cert | |
  17. | ssl_cipher | |
  18. | ssl_crl | |
  19. | ssl_crlpath | |
  20. | ssl_key | |
  21. +---------------+----------+
  22. 9 rows in set (0.00 sec)

mysql err log 显示: 正常

【结论1】MySQL 5.7.27 版本及以下,若jdbc连接串错误地配置了 useSSL=true,并不会有问题。因为数据库默认关闭 SSL,所以连接实际上并不会使用到 SSL,一切正常。

  • [5.7.28]
  1. mysql> show variables like '%ssl%';
  2. +---------------+-----------------+
  3. | Variable_name | Value |
  4. +---------------+-----------------+
  5. | have_openssl | YES |
  6. | have_ssl | YES |
  7. | ssl_ca | ca.pem |
  8. | ssl_capath | |
  9. | ssl_cert | server-cert.pem |
  10. | ssl_cipher | |
  11. | ssl_crl | |
  12. | ssl_crlpath | |
  13. | ssl_key | server-key.pem |
  14. +---------------+-----------------+
  15. 9 rows in set (0.00 sec)

Tomcat可能出如下异常:

  1. 上面日志,能看出:
  2. 1) SSL 相关异常。
  3. 2)1个关键的报错: 握手异常,且有证书相关的报错。
  4. Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
  5. 后经测试证实: jdbc 连接要求 SSL 证书认证要一起使用。

mysql err log 显示: Bad handshake

  1. 2020-05-06T19:12:13.107321+08:00 2 [Note] Bad handshake

【结论2】MySQL5.7.28 版本及以后:

  1. 若jdbc连接串错误地配置了 useSSL=true,会有问题,因为数据库默认开启 SSL。所以,连接实际上应用连接会真的去使用 SSL,但是因为证书问题,将导致连接失败。
  2. 若jdbc连接去掉 useSSL=true (≈ useSSL=false): 发现一切正常,但 tomcat 日志有以下的 warnings:
  1. Wed May 06 20:54:47 CST 2020 WARN: Establishing SSL connection without servers identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isnt set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
  2. + 不建议在未经服务器身份验证的情况下建立 SSL 连接。
  3. + 根据 MySQL 5.5.45+、5.6.26+ 5.7.6+ 的要求,如果未设置显式选项,则默认情况下必须建立 SSL 连接。
  4. + 为了符合不使用 SSL 的现有应用程序,verifyServerCertificate 属性设置为"false"
  5. + 您需要通过设置 useSSL=false 显式禁用 SSL,或设置 useSSL=true 并为服务器证书验证提供 truststore

5 Openssh命令

ssh的配置文件: /etc/ssh/ssh_config

  1. # $OpenBSD: ssh_config,v 1.30 2016/02/20 23:06:23 sobrado Exp $
  2. # This is the ssh client system-wide configuration file. See
  3. # ssh_config(5) for more information. This file provides defaults for
  4. # users, and the values can be changed in per-user configuration files
  5. # or on the command line.
  6. # Configuration data is parsed as follows:
  7. # 1. command line options
  8. # 2. user-specific file
  9. # 3. system-wide file
  10. # Any configuration value is only changed the first time it is set.
  11. # Thus, host-specific definitions should be at the beginning of the
  12. # configuration file, and defaults at the end.
  13. # Site-wide defaults for some commonly used options. For a comprehensive
  14. # list of available options, their meanings and defaults, please see the
  15. # ssh_config(5) man page.
  16. # Host *
  17. # ForwardAgent no
  18. # ForwardX11 no
  19. # RhostsRSAAuthentication no
  20. # RSAAuthentication yes
  21. # PasswordAuthentication yes
  22. # HostbasedAuthentication no
  23. # GSSAPIAuthentication no
  24. # GSSAPIDelegateCredentials no
  25. # GSSAPIKeyExchange no
  26. # GSSAPITrustDNS no
  27. # BatchMode no
  28. # CheckHostIP yes
  29. # AddressFamily any
  30. # ConnectTimeout 0
  31. # StrictHostKeyChecking ask
  32. # IdentityFile ~/.ssh/identity
  33. # IdentityFile ~/.ssh/id_rsa
  34. # IdentityFile ~/.ssh/id_dsa
  35. # IdentityFile ~/.ssh/id_ecdsa
  36. # IdentityFile ~/.ssh/id_ed25519
  37. # Port 22
  38. # Protocol 2
  39. # Cipher 3des
  40. # Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
  41. # MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
  42. # EscapeChar ~
  43. # Tunnel no
  44. # TunnelDevice any:any
  45. # PermitLocalCommand no
  46. # VisualHostKey no
  47. # ProxyCommand ssh -q -W %h:%p gateway.example.com
  48. # RekeyLimit 1G 1h
  49. #
  50. # Uncomment this if you want to use .local domain
  51. # Host *.local
  52. # CheckHostIP no
  53. Host *
  54. GSSAPIAuthentication yes
  55. # If this option is set to yes then remote X11 clients will have full access
  56. # to the original X11 display. As virtually no X11 client supports the untrusted
  57. # mode correctly we set this to yes.
  58. ForwardX11Trusted yes
  59. # Send locale-related environment variables
  60. SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
  61. SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
  62. SendEnv LC_IDENTIFICATION LC_ALL LANGUAGE
  63. SendEnv XMODIFIERS

sshd的配置文件: /etc/ssh/sshd_config

  1. # /etc/sshd/ssh_config
  2. # $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $
  3. # This is the sshd server system-wide configuration file. See
  4. # sshd_config(5) for more information.
  5. # This sshd was compiled with PATH=/usr/local/bin:/usr/bin
  6. # The strategy used for options in the default sshd_config shipped with
  7. # OpenSSH is to specify options with their default value where
  8. # possible, but leave them commented. Uncommented options override the
  9. # default value.
  10. # If you want to change the port on a SELinux system, you have to tell
  11. # SELinux about this change.
  12. # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
  13. #
  14. #Port 22
  15. #AddressFamily any
  16. #ListenAddress 0.0.0.0
  17. #ListenAddress ::
  18. HostKey /etc/ssh/ssh_host_rsa_key
  19. #HostKey /etc/ssh/ssh_host_dsa_key
  20. HostKey /etc/ssh/ssh_host_ecdsa_key
  21. HostKey /etc/ssh/ssh_host_ed25519_key
  22. # Ciphers and keying
  23. #RekeyLimit default none
  24. # Logging
  25. #SyslogFacility AUTH
  26. SyslogFacility AUTHPRIV
  27. #LogLevel INFO
  28. # Authentication:
  29. #LoginGraceTime 2m
  30. #PermitRootLogin yes
  31. #StrictModes yes
  32. #MaxAuthTries 6
  33. #MaxSessions 10
  34. #PubkeyAuthentication yes
  35. # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
  36. # but this is overridden so installations will only check .ssh/authorized_keys
  37. AuthorizedKeysFile .ssh/authorized_keys
  38. #AuthorizedPrincipalsFile none
  39. #AuthorizedKeysCommand none
  40. #AuthorizedKeysCommandUser nobody
  41. # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
  42. #HostbasedAuthentication no
  43. # Change to yes if you don't trust ~/.ssh/known_hosts for
  44. # HostbasedAuthentication
  45. #IgnoreUserKnownHosts no
  46. # Don't read the user's ~/.rhosts and ~/.shosts files
  47. #IgnoreRhosts yes
  48. # To disable tunneled clear text passwords, change to no here!
  49. #PasswordAuthentication yes
  50. #PermitEmptyPasswords no
  51. PasswordAuthentication yes
  52. # Change to no to disable s/key passwords
  53. #ChallengeResponseAuthentication yes
  54. ChallengeResponseAuthentication no
  55. # Kerberos options
  56. #KerberosAuthentication no
  57. #KerberosOrLocalPasswd yes
  58. #KerberosTicketCleanup yes
  59. #KerberosGetAFSToken no
  60. #KerberosUseKuserok yes
  61. # GSSAPI options
  62. GSSAPIAuthentication yes
  63. GSSAPICleanupCredentials no
  64. #GSSAPIStrictAcceptorCheck yes
  65. #GSSAPIKeyExchange no
  66. #GSSAPIEnablek5users no
  67. # Set this to 'yes' to enable PAM authentication, account processing,
  68. # and session processing. If this is enabled, PAM authentication will
  69. # be allowed through the ChallengeResponseAuthentication and
  70. # PasswordAuthentication. Depending on your PAM configuration,
  71. # PAM authentication via ChallengeResponseAuthentication may bypass
  72. # the setting of "PermitRootLogin without-password".
  73. # If you just want the PAM account and session checks to run without
  74. # PAM authentication, then enable this but set PasswordAuthentication
  75. # and ChallengeResponseAuthentication to 'no'.
  76. # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
  77. # problems.
  78. UsePAM yes
  79. #AllowAgentForwarding yes
  80. #AllowTcpForwarding yes
  81. #GatewayPorts no
  82. X11Forwarding yes
  83. #X11DisplayOffset 10
  84. #X11UseLocalhost yes
  85. #PermitTTY yes
  86. #PrintMotd yes
  87. #PrintLastLog yes
  88. #TCPKeepAlive yes
  89. #UseLogin no
  90. #UsePrivilegeSeparation sandbox
  91. #PermitUserEnvironment no
  92. #Compression delayed
  93. #ClientAliveInterval 0
  94. #ClientAliveCountMax 3
  95. #ShowPatchLevel no
  96. #UseDNS yes
  97. #PidFile /var/run/sshd.pid
  98. #MaxStartups 10:30:100
  99. #PermitTunnel no
  100. #ChrootDirectory none
  101. #VersionAddendum none
  102. # no default banner path
  103. #Banner none
  104. # Accept locale-related environment variables
  105. AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
  106. AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
  107. AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
  108. AcceptEnv XMODIFIERS
  109. # override default of no subsystems
  110. Subsystem sftp /usr/libexec/openssh/sftp-server
  111. # Example of overriding settings on a per-user basis
  112. #Match User anoncvs
  113. # X11Forwarding no
  114. # AllowTcpForwarding no
  115. # PermitTTY no
  116. # ForceCommand cvs server

查看sshd服务支持的cipher/加密算法

  • 方法1:ssh -Q cipher
  1. # ssh -Q cipher
  2. 3des-cbc
  3. blowfish-cbc
  4. cast128-cbc
  5. arcfour
  6. arcfour128
  7. arcfour256
  8. aes128-cbc
  9. aes192-cbc
  10. aes256-cbc
  11. rijndael-cbc@lysator.liu.se
  12. aes128-ctr
  13. aes192-ctr
  14. aes256-ctr
  15. aes128-gcm@openssh.com
  16. aes256-gcm@openssh.com
  17. chacha20-poly1305@openssh.com
  • 方法2:使用man sshd_config查看Ciphers项可以看到sshd支持的算法(如下图所示)
  1. # man sshd_config
  2. ...
  3. Ciphers
  4. Specifies the ciphers allowed. Multiple ciphers must be comma-separated. If the specified value begins with a ‘+’ character, then the speci
  5. fied ciphers will be appended to the default set instead of replacing them.
  6. The supported ciphers are:
  7. 3des-cbc
  8. aes128-cbc
  9. aes192-cbc
  10. aes256-cbc
  11. aes128-ctr
  12. aes192-ctr
  13. aes256-ctr
  14. aes128-gcm@openssh.com
  15. aes256-gcm@openssh.com
  16. arcfour
  17. arcfour128
  18. arcfour256
  19. blowfish-cbc
  20. cast128-cbc
  21. chacha20-poly1305@openssh.com
  22. The default is:
  23. chacha20-poly1305@openssh.com,
  24. aes128-ctr,aes192-ctr,aes256-ctr,
  25. aes128-gcm@openssh.com,aes256-gcm@openssh.com,
  26. aes128-cbc,aes192-cbc,aes256-cbc,
  27. blowfish-cbc,cast128-cbc,3des-cbc
  28. The list of available ciphers may also be obtained using "ssh -Q cipher".
  29. ...

使用指定的(订制)加密算法

(未亲测)

  1. ssh cipher encryption custom aes128-ctr:aes192-ctr:aes256-ctr

X 参考/推荐文献

[网络/SSH]OpenSSH: sshd / sftp-server / ssh-agent | ssh / scp / sftp | OpenSSL的更多相关文章

  1. ssh和sshd服务

    1.1 对称加密和非对称加密 对称加密:加密和解密使用一样的算法,只要解密时提供与加密时一致的密码就可以完成解密.例如QQ登录密码,银行卡密码,只要保证密码正确就可以. 非对称加密:通过公钥(publ ...

  2. 【原创】大叔问题定位分享(28)openssh升级到7.4之后ssh跳转异常

    服务器集群之间忽然ssh跳转不通 # ssh 192.168.0.1The authenticity of host '192.168.0.1 (192.168.0.1)' can't be esta ...

  3. ssh - OpenSSH SSH 客户端 (远程登录程序)

    总览 (SYNOPSIS) ssh [-l login_name ] hostname | user@hostname [command ] ssh -words [-afgknqstvxACNTX1 ...

  4. FTP 与 SSH 的安全性对比, 以及FTP,SSH,SFTP,SCP 的关系简单解析!

    FTP 与 SSH 的安全性对比? ftP: http://baike.baidu.com/subview/369/6149695.htm TCP/IP协议中,FTP标准命令TCP端口号为21,Por ...

  5. 使用工具SecureCRT通过ssh远程连接Windows server 2019

    Windows Server 2019 开通SSH Server服务 在需要安裝的ws2019开启powershell,执行安装 openssh server 指令 Add-WindowsCapabi ...

  6. ssh/openssh

    http://www.cnblogs.com/wwufengg/articles/ssh-openssh-detail.html http://www.cnblogs.com/jjkv3/archiv ...

  7. 解决 ssh 登录到ubuntu server 慢的问题

    最近在服务器上使用ubuntu系统,服务器上开启sshd服务,在客户端处使用ssh登录到服务器的时候出现卡顿的现象. 在网上搜索了解决方案,主要是: 1. 修改服务器的 /etc/ssh/sshd_c ...

  8. SCP和SFTP(都使用SSH。但SCP上传不能中断,而SFTP可以续传,这是最大区别)

    不管SCP还是SFTP,都是SSH的功能之一.都是使用SSH协议来传输文件的. 不用说文件内容,就是登录时的用户信息都是经过SSH加密后才传输的,所以说SCP和SFTP实现了安全的文件传输. SCP和 ...

  9. SSH连接Linux的Server超时

    SSH连接Linux的Server超时 http://blog.csdn.net/cheng830306/article/details/21796865

  10. Ubuntu 安装 SSH server 并配置 SSH 无密码登录

    https://hinine.com/install-and-configure-ssh-server-on-ubuntu/ Ubuntu 安装 SSH server 并配置 SSH 无密码登录 发表 ...

随机推荐

  1. C# net core 从文件流中获取文件头、匹配文件类型

    常用文件的文件头如下: (以前六位为准) JPEG (jpg),文件头:FFD8FF PNG (png),文件头:89504E47 GIF (gif),文件头:47494638 TIFF (tif), ...

  2. vue iview前端直接上传OSS

    1. 首先安装oss npm install ali-oss --save 2. // template部分 <Upload ref="upload" type=" ...

  3. MPC

    Just for anyone searching for code. I found it here: https://drive.google.com/drive/folders/0BzLEHBD ...

  4. new一个实例的原理及过程

    前提,要明白new出来的实例是什么,包含了哪些内容? 请看一下举例代码↓↓↓↓ function Person(name,age){ this.name = name; this.age = age; ...

  5. RabbitMQ安装失败 地址提示错误

    最后设置为: D:\RabbitMQ\rabbitmq_server-3.7.10-rc.3\sbin>set ERLANG_HOME=D:\Erlang\erl10.2

  6. vue3.0的生命周期函数

    stetup(){}在 生命周期函数 系列中的优先级 〇setup(){ //优先级最高 处于created生命周期之前的函数,是无法访问data,methods中的数据是无法访问到的,setup中的 ...

  7. 8-WebShell总结

    WebShell 1.webshell介绍 在计算机科学中,Shell 俗称壳(用来区别"核"),是指"为使用者提供操作界面"的软件(命令解释器).类似于win ...

  8. jmeter--负载测试

    负载测试 1. jmeter插件处理 2. 下载负载测试计划所需要插件 3. 负载测试计划 4. 波浪形的测试计划--测试服务器的稳定性 一般用于测试稳定的场景测试(有规律的活动/场景/接口请求等等, ...

  9. Windows10电源选项:睡眠、休眠、启用快速启动

    参考链接: http://www.dnpz.net/diannaozhishi/2223.html http://www.cfan.com.cn/2018/0118/130151.shtml 在介绍w ...

  10. 如何用猿大师播放器在网页上同时播放20路以上海康威视高分辨率(1920*1080)摄像头RTSP视频流?

    问: 同时播放分辨率为1920*1080的高清分辨率的摄像头视频流,找了很长时间试过无数方法均不能满足,服务器转码方案卡顿非常严重,几乎不能播放.了解到猿大师可以用到本机的硬件解码和加速,播放高清视频 ...