步骤一:确定 CRYPTO_POLICY 参数没有生效
1.1 确定 /etc/ssh/sshd_config 文件
# vim /etc/ssh/sshd_config
确保部分内容如下:
......
Include /etc/ssh/sshd_config.d/*.conf
......
Include /usr/etc/ssh/sshd_config.d/*.conf
......
1.2 确定 /usr/etc/ssh/sshd_config.d/*.conf 文件或者 /etc/ssh/sshd_config.d/*.conf 文件
# vim /etc/ssh/sshd_config.d/*.conf
或者:
# vim /usr/etc/ssh/sshd_config.d/*.conf
确保部分内容如下:
......
Include /etc/crypto-policies/back-ends/opensshserver.config
......
步骤二:在 /etc/crypto-policies/back-ends/opensshserver.config 配置文件中确认要使用的 Ciphers、MACs 和 KexAlgorithm 参数
2.1 备份 /etc/crypto-policies/back-ends/opensshserver.config 配置文件
# cp /etc/crypto-policies/back-ends/opensshserver.config /etc/crypto-policies/back-ends/opensshserver.config.backup
2.2 修改 /etc/crypto-policies/back-ends/opensshserver.config 配置文件
# vim /etc/crypto-policies/back-ends/opensshserver.config
添加需要使用的 SSH 算法 (algorithms) 和加密方式 (ciphers):
(内容略)
(注意:如果需要使用的 SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm) ,已包含在其中了则可以不用添加)
2.3 显示目前正在被使用的 SSH 算法 (algorithms) 和加密方式 (ciphers)
# cat /etc/crypto-policies/back-ends/opensshserver.config
Ciphers aes256-gcm@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
MACs hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,hmac-sha2-512
GSSAPIKexAlgorithms gss-nistp256-sha256-,gss-group14-sha256-,gss-group16-sha512-
KexAlgorithms ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512
HostKeyAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com
PubkeyAcceptedAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com
HostbasedAcceptedAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com
CASignatureAlgorithms ecdsa-sha2-nistp256,sk-ecdsa-sha2-nistp256@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,sk-ssh-ed25519@openssh.com,rsa-sha2-256,rsa-sha2-512
RequiredRSASize 2048
(补充:这里以显示 openSUSE & SLES 默认使用的 SSH 加密方式 (cipher)、信息验证代码 (message authentication code) 和算法 (algorithm) 为例)
步骤三:让在 /etc/crypto-policies/back-ends/opensshserver.config 配置文件中添加要使用的 SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm) 生效
# systemctl restart sshd
步骤四:测试 SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm)
4.1 测试 SSH 加密方式 (cipher)
4.1.1 测试某个 SSH 加密方式 (cipher)
# ssh -vv -oCiphers=3des-cbc -oPort=22 192.168.0.1
(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 3des-cbc SSH 加密方式 (cipher) 为例)
4.1.2 测试多个 SSH 加密方式 (cipher)
# ssh -vv -oCiphers=3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc -oPort=22 192.168.0.1
(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 3des-cbc、aes128-cbc、aes192-cbc 和 aes256-cbc SSH 加密方式 (cipher) 为例)
4.2 测试 SSH 信息验证代码 (message authentication code)
4.2.1 测试某个 SSH 信息验证代码 (MESSAGE AUTHENTICATION CODE)
# ssh -vv -oMACs=hmac-md5 -oPort=22 192.168.0.1
(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 hmac-md5 SSH 信息验证代码 (message authentication code) 为例)
4.2.2 测试多个 SSH 信息验证代码 (MESSAGE AUTHENTICATION CODE)
# ssh -vv -oMACs=hmac-md5,hmac-md5-96,hmac-sha1,hmac-sha1-96,hmac-md5-etm@openssh.com,hmac-md5-96-etm@openssh.com -oPort=22 192.168.0.1
(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 hmac-md5、hmac-md5-96、hmac-sha1、hmac-sha1-96、hmac-md5-etm@openssh.com 和 hmac-md5-96-etm@openssh.com SSH 信息验证代码 (message authentication code) 为例)
4.3 显示所有在使用的 SSH 加密方式 (cipher) 、信息验证代码 (message authentication code) 和算法 (algorithm)
4.3.1 使用 SSHD 命令显示所有在使用的加密方式 (cipher) 、信息验证代码 (MESSAGE AUTHENTICATION CODE)
# sshd -T | egrep -i "ciphers|macs|kexalgorithms"
4.3.2 使用 NMAP 命令显示所有在使用的 SSH 加密方式 (cipher) 、信息验证代码 (MESSAGE AUTHENTICATION CODE) 和算法 (ALGORITHM)
# nmap --script ssh2-enum-algos -sV -p 22 127.0.0.1
(补充:这里以测试本地的 22 端口为例)
4.3.3 使用 NMAP 命令显示所有在使用的 SSH 加密方式 (cipher) 、信息验证代码 (MESSAGE AUTHENTICATION CODE) 和算法 (ALGORITHM)
# ssh -vvv 127.0.0.1
(补充:这里以测试本地的 22 端口为例)
