SSH:如何禁用弱密码?

rɑː*_*dʒɑ 63 ssh encryption

我组织的安全团队告诉我们禁用弱密码,因为它们发出弱密钥。

  arcfour
  arcfour128
  arcfour256
Run Code Online (Sandbox Code Playgroud)

但是我尝试在 ssh_config 和 sshd_config 文件中查找这些密码,但发现它们已注释。

 grep arcfour *
ssh_config:#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
Run Code Online (Sandbox Code Playgroud)

我还应该在哪里检查以从 SSH 禁用这些密码?

Ulr*_*arz 51

如果您没有ssh_config使用Ciphers关键字设置明确的密码列表,则根据man 5 ssh_config(客户端)和man 5 sshd_config(服务器端)的默认值是:

            aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,
            aes128-gcm@openssh.com,aes256-gcm@openssh.com,
            chacha20-poly1305@openssh.com,
            aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,
            aes256-cbc,arcfour
Run Code Online (Sandbox Code Playgroud)

请注意 arcfour 密码的存在。因此,您可能必须为 明确设置更严格的值Ciphers

ssh -Q cipher客户会告诉您您的客户可以支持哪些方案。请注意,此列表不受 中指定的密码列表的影响ssh_config。从 中删除密码ssh_config不会将其从 的输出中删除ssh -Q cipher。此外,使用显式指定密码ssh-c选项将覆盖您设置的密码限制列表,ssh_config并可能允许您使用弱密码。这是一项功能,允许您使用ssh客户端与不支持较新的更强密码的过时 SSH 服务器进行通信。

nmap --script ssh2-enum-algos -sV -p <port> <host> 会告诉您您的服务器支持哪些方案。

  • 抱歉,`ssh_config`是客户端配置,服务器端配置是`sshd_config`,请尝试一下。(那里也称为“密码”。) (2认同)

小智 42

要在 SSH 服务器上禁用 RC4 并使用安全密码,请在 /etc/ssh/sshd_config

ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
Run Code Online (Sandbox Code Playgroud)

或者,如果您不想指定密码而只想去除不安全的密码,请改为在命令行上运行此命令(在 sudo 模式下):

sshd -T | grep ciphers | sed -e "s/\(3des-cbc\|aes128-cbc\|aes192-cbc\|aes256-cbc\|arcfour\|arcfour128\|arcfour256\|blowfish-cbc\|cast128-cbc\|rijndael-cbc@lysator.liu.se\)\,\?//g" >> /etc/ssh/sshd_config
Run Code Online (Sandbox Code Playgroud)

您可以通过以下方式检查服务器当前使用的密码:

sudo sshd -T | grep ciphers | perl -pe 's/,/\n/g' | sort -u
Run Code Online (Sandbox Code Playgroud)

确保您的 ssh 客户端可以使用这些密码,运行

ssh -Q cipher | sort -u
Run Code Online (Sandbox Code Playgroud)

查看列表。

您还可以指示您的 SSH 客户端仅与远程服务器协商安全密码。在/etc/ssh/ssh_config集:

Host *
    ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
Run Code Online (Sandbox Code Playgroud)

以上片段来自这里
要测试您的服务器的设置,您可以使用ssh-audit


Spa*_*dog 34

明确指定密码列表的问题在于您必须在新密码出现时手动添加它们。相反,只需列出要删除的密码,并在列表(不是每个单独的密码)前面加上“-”字符。所以在这种情况下,密码行应该是:

Ciphers -arcfour*
Run Code Online (Sandbox Code Playgroud)

或者,如果您更喜欢:

Ciphers -arcfour,arcfour128,arcfour256
Run Code Online (Sandbox Code Playgroud)

密码选项上的 sshd_config 手册页(自 OpenSSH 7.5 起,于 2017 年 3 月 20 日发布):

如果指定的值以“+”字符开头,则指定的密码将附加到默认设置中而不是替换它们。如果指定的值以“-”字符开头,则指定的密码(包括通配符)将从默认设置中删除而不是替换它们。

这也适用于KexAlgorithmsMACs选项。

  • 尽管我希望拥有此功能,但我相信不再支持 `-` 前缀,这就是 @AbhinavKinagi 出现错误的原因。事实上,检查:``bash man sshd_config``你会看到:*指定允许的密码。多个密码必须以逗号分隔。如果指定的值以“+”字符开头,则指定的密码将附加到默认集而不是替换它们。* (3认同)

elb*_*rna 6

如何禁用弱 ssh 密码,在 Fedora 29 上进行了 100% 工作测试。\n问题:\nNessus 报告我的 samba4 服务器使用不强的密码 aes256-cbc 和 aes128-cbc。\n所以我将这些行放入/etc/ssh/sshd_config

\n\n
MACs hmac-sha2-512,hmac-sha2-256\nCiphers aes256-ctr,aes192-ctr,aes128-ctr\nKexAlgorithms diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,curve25519-sha256,curve25519-sha256@libssh.org\n
Run Code Online (Sandbox Code Playgroud)\n\n

Et voil\xc3\xa0!...它仍然使用 cbc 密码,因为这个命令有效:(

\n\n
ssh -c aes256-cbc samba4\n
Run Code Online (Sandbox Code Playgroud)\n\n

所以我检查了有用的 systemd,发现 sshd 服务正在使用另一个文件作为密码

\n\n
/etc/crypto-policies/back-ends/opensshserver.config\n
Run Code Online (Sandbox Code Playgroud)\n\n

备份文件以确保安全

\n\n
cp /etc/crypto-policies/back-ends/opensshserver.config     /etc/crypto-policies/back-ends/opensshserver.config.old\n
Run Code Online (Sandbox Code Playgroud)\n\n

编辑它,并删除 cbc 密码。\n重新启动服务

\n\n
systemctl restart sshd\n
Run Code Online (Sandbox Code Playgroud)\n\n

最后测试,工作正常..cbc 已禁用。

\n\n
ssh -c aes256-cbc samba4\nUnable to negotiate with 192.168.0.48 port 22: no matching cipher found. Their offer: aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr\n
Run Code Online (Sandbox Code Playgroud)\n