注意:
RHEL 8 的 SSH 加密算法默认会使用来自 crypto policies 系统的全局 SSH 加密算法,而此方法将让 SSH 使用单独设置的 SSH 加密算法。
正文:
步骤一:启用 SSH 加密算法
1.1 备份 /etc/sysconfig/sshd 配置文件
# cp /etc/sysconfig/sshd /etc/sysconfig/sshd_backup
1.2 修改 /etc/sysconfig/sshd 配置文件
# vim /etc/sysconfig/sshd
将以下内容:
# CRYPTO_POLICY=
修改为:
CRYPTO_POLICY=
步骤二:在 /etc/ssh/sshd_config 配置文件中设置要使用的 SSH 加密算法
2.1 备份 /etc/ssh/sshd_config 配置文件
# cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup
2.2 在 /etc/ssh/sshd_config 配置文件中添加要使用的 SSH 加密算法
# vim /etc/ssh/sshd_config
添加以下内容:
......
Ciphers aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512,hmac-sha2-256
KexAlgorithms ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
(
补充:这里以使用:
1) aes256-ctr、aes192-ctr 和 aes128-ctr SSH Ciphers 加密算法
2) hmac-sha2-512 和 hmac-sha2-256 SSH MACs 加密算法
3) ecdh-sha2-nistp521、ecdh-sha2-nistp384、ecdh-sha2-nistp256 和 diffie-hellman-group-exchange-sha256 SSH KexAlgorithms 加密算法
为例
)
2.3 让在 /etc/ssh/sshd_config 配置文件中添加要使用的 SSH 加密算法生效
# systemctl restart sshd
步骤三:测试 SSH 加密算法
3.1 测试 SSH Ciphers 加密算法
3.1.1 测试某个 SSH Ciphers 加密算法
# ssh -vv -oCiphers=3des-cbc -oPort=22 192.168.0.1
(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 3des-cbc SSH Ciphers 加密算法为例)
3.1.2 测试多个 SSH Ciphers 加密算法
# 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 Ciphers 加密算法为例)
3.2 测试 SSH MACs 加密算法
3.2.1 测试某个 SSH Ciphers 加密算法
# ssh -vv -oMACs=hmac-md5 -oPort=22 192.168.0.1
(补充:这里以测试 IP 地址是 192.168.0.1,端口号是 22,有没有启用 hmac-md5 SSH MACs 加密算法为例)
3.2.2 测试多个 SSH Ciphers 加密算法
# 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 MACs 加密算法为例)