Skip to content

Eternal Center

  • Single Node (单节点)
    • System (系统)
    • Service (服务)
    • Database (数据库)
    • Container (容器)
    • Virtualization (虚拟化)
  • Multi Node (多节点)
    • Cluster (集群)
    • Big Data (大数据)
    • Cloud Computing (云计算)
    • Batch Processing (批量处理)
  • Other (其它)
    • Ideas (思路)
    • Language (语言)
    • Project (项目)
  • Eternity (永恒)
    • Creations (创作)
    • Classics (经典)
    • Chronicle (编年史)
    • News (消息)
Posted on August 29, 2022August 29, 2022 by Mingyu Zhu

[步骤] Linux SSH 加密算法的设置 (不使用来自 crypto policies 的系统全局 SSH 加密算法) (RHEL 8 版)

  • 注意:
  • 正文:
    • 步骤一:启用 SSH 加密算法
      • 1.1 备份 /etc/sysconfig/sshd 配置文件
      • 1.2 修改 /etc/sysconfig/sshd 配置文件
    • 步骤二:设置 SSH 的加密算法
      • 2.1 在 /etc/crypto-policies/back-ends/opensshserver.config 配置文件中确认要使用的 SSH 加密算法属性
        • 2.1.1 修改 /etc/crypto-policies/back-ends/opensshserver.config 配置文件
        • 2.1.2 显示目前正在被使用的 SSH 加密算法
      • 2.2 在 /etc/ssh/sshd_config 配置文件中设置要使用的 SSH 加密算法
        • 2.2.1 备份 /etc/ssh/sshd_config 配置文件
        • 2.2.2 在 /etc/ssh/sshd_config 配置文件中添加要使用的 SSH 加密算法
        • 2.2.3 让在 /etc/ssh/sshd_config 配置文件中添加要使用的 SSH 加密算法生效
    • 步骤三:测试 SSH 加密算法
      • 3.1 测试 SSH Ciphers 加密算法
        • 3.1.1 测试某个 SSH Ciphers 加密算法
        • 3.1.2 测试多个 SSH Ciphers 加密算法
      • 3.2 测试 SSH MACs 加密算法
        • 3.2.1 测试某个 SSH Ciphers 加密算法
        • 3.2.2 测试多个 SSH Ciphers 加密算法

注意:

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=

步骤二:设置 SSH 的加密算法

2.1 在 /etc/crypto-policies/back-ends/opensshserver.config 配置文件中确认要使用的 SSH 加密算法属性

2.1.1 修改 /etc/crypto-policies/back-ends/opensshserver.config 配置文件
# vim /etc/crypto-policies/back-ends/opensshserver.config

添加需要使用的 SSH 加密算法属性:

(内容略)

(注意:如果需要使用的 SSH 加密算法已包含在其中了则可以不用添加)

2.1.2 显示目前正在被使用的 SSH 加密算法
# printf "%s\n" $(source /etc/crypto-policies/back-ends/opensshserver.config; echo $CRYPTO_POLICY) | cut -c3-
Ciphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc,aes128-gcm@openssh.com,aes128-ctr,aes128-cbc
MACs=hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,umac-128@openssh.com,hmac-sha2-512
GSSAPIKexAlgorithms=gss-curve25519-sha256-,gss-nistp256-sha256-,gss-group14-sha256-,gss-group16-sha512-,gss-gex-sha1-,gss-group14-sha1-
KexAlgorithms=curve25519-sha256,curve25519-sha256@libssh.org,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,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
HostKeyAlgorithms=ecdsa-sha2-nistp256,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,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,ssh-rsa,ssh-rsa-cert-v01@openssh.com
PubkeyAcceptedKeyTypes=ecdsa-sha2-nistp256,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,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert-v01@openssh.com,ssh-rsa,ssh-rsa-cert-v01@openssh.com
CASignatureAlgorithms=ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,rsa-sha2-256,rsa-sha2-512,ssh-rsa

(补充:这里以显示 RHEL8 默认使用的 SSH 加密算法为例)

2.2 在 /etc/ssh/sshd_config 配置文件中设置要使用的 SSH 加密算法

2.2.1 备份 /etc/ssh/sshd_config 配置文件
# cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup
2.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.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 加密算法为例)

CategoriesChinese (中文), System (系统), System Login Security (系统登录安全), System Port Security (系统端口安全), System Security (系统安全)

Post navigation

Previous PostPrevious [内容] nftables 防火墙策略文件的常用规则
Next PostNext [排错] 解决 Linux 执行 Shell 脚本时报错 “[: ……: unary operator expected”

Aspiration (愿景):

Everyone can achieve self achievement and self happiness fairly

每个人都能公平地实现自我成就和自我幸福

Position (位置):

Running on Evolution Host and DigitalOcean

正在 Evolution Host 和 DigitalOcean 上运行

Logo (徽标):

Additional Information (其他信息):

About Manual Clone Contact
Disclaimer Donation Friendly Links
关于 说明书 克隆 联系
免责申明 捐赠 友情链接

Standby IP Address (备用 IP 地址):

152.69.204.95  150.230.63.10  Please configure before use / 请先配置再使用

Search Outside Website (站外搜索):

Google Wikipedia Bing
Proudly powered by LNMP Proudly powered by WordPress