问题及解决

ssh_exchange_identification: read: Connection reset by peer
原因:一般是因为源地址限制导致的

Permission denied (publickey,keyboard-interactive,hostbased).
原因:客户端和服务端认证方法不匹配,最后定位因为是server端使用了keyboard-interactive认证方法,而客户端只有password,publickey。

解决:修改server上的sshd_config将AuthenticationMethods注释掉使用默认,或者配置成和客户端使用的一致。

man文档说明

The available authentication methods are:

Qq gssapi-with-mic , Qq hostbased , Qq keyboard-interactive ,  Qq  none  (used for access to password-less accounts when PermitEmptyPasswords is enabled), Qq password and Qq publickey .

参数说明

SSH 协议中支持的几种认证方法(这些认证方法除了在AuthenticationMethods 配置,同时也需要明确启用才行,例如:PasswordAuthentication yes):

  1. gssapi-with-mic:(GSSAPIAuthentication yes)

    • 描述: 使用 Generic Security Service API(GSSAPI)进行身份验证,通常与 Kerberos 认证一起使用。
    • 安全性: 高。Kerberos 提供了强大的身份验证和单点登录机制。
  2. hostbased:(HostbasedAuthentication yes)

    • 描述: 基于主机的身份验证,通常使用主机和用户的密钥进行验证。
    • 安全性: 依赖于密钥的管理和分发,通常不推荐在不受信任的网络中使用。
  3. keyboard-interactive:(KbdInteractiveAuthentication yes)

    • 描述: 交互式的身份验证方式,通常包括通过键盘输入密码或其他信息进行身份验证。
    • 安全性: 取决于密码的复杂性和用户的安全实践。支持交互式操作,适用于需要用户输入的场景。
  4. none:(PermitEmptyPasswords yes)

    • 描述: 表示没有使用任何身份验证方法,通常用于访问启用了空密码(PermitEmptyPasswords)的帐户。
    • 安全性: 低。在生产环境中,通常应禁用空密码。
  5. password:(PasswordAuthentication yes)

    • 描述: 使用密码进行身份验证。
    • 安全性: 取决于密码的复杂性。在不安全的网络中,可能容易受到中间人攻击。
  6. publickey:(PubkeyAuthentication yes)

    • 描述: 使用公钥进行身份验证,通常使用用户的 SSH 密钥对。
    • 安全性: 高。公钥加密提供了强大的安全性,特别是当密钥足够长时。

这些方法提供了不同层次的安全性和适用于不同的使用场景。在实际使用中,通常推荐使用公钥(publickey)进行身份验证,因为它提供了较高的安全性和便利性。同时,使用 GSSAPI 进行 Kerberos 身份验证也是一种常见的做法,尤其在企业环境中。其他方法的使用通常受到特定需求和安全实践的限制。

特别说明:UsePAM参数

UsePAM使能Pluggable Authentication Module接口。如果设置为yes,除了PAM帐户和会话模块处理所有身份验证类型之外,还将启用使用KbdInteractiveAuthentication和PasswordAuthentication的PAM身份验证。

由于PAM keyboard-interactive 身份验证通常扮演与密码身份验证相同的角色,因此应该禁用PasswordAuthentication或KbdInteractiveAuthentication。

如果启用了UsePAM,您将无法以非root用户的身份运行sshd(8)。默认为no。在openssh9左右版本开始不支持UsePAM参数了

特别说明:sshd_config参数重复配置

sshd_config配置文件相同属性只有第一条生效

1、配置多条,例如:
PasswordAuthentication yes
PasswordAuthentication no


2、加载配置
systemctl reload sshd  


3、检查生效情况
sshd -T|grep -i PasswordAuthentication
passwordauthentication yes

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐