Resolving Git SSH Connection Error: no matching host key type found and Security Considerations

Nov 20, 2025 · Programming · 12 views · 7.8

Keywords: Git | SSH | ssh-rsa | host key | security algorithms

Abstract: This article provides an in-depth analysis of the 'no matching host key type found. Their offer: ssh-rsa' error encountered when using Git with SSH. It explains the root cause: OpenSSH disabling the insecure ssh-rsa (RSA/SHA-1) signature algorithm by default since version 8.2. The compatibility issues with services like Azure DevOps are detailed, along with a temporary solution via modifying the ~/.ssh/config file. The article emphasizes the security risks of this workaround, recommending HTTPS or migrating to Git hosting services that support safer algorithms (e.g., rsa-sha2-256/512), and calls for service providers to upgrade promptly.

Error Phenomenon and Background

When performing remote repository operations with Git (e.g., git pull or git push), some users encounter the following error:

$ git pull
Unable to negotiate with 172.16.42.42 port 22: no matching host key type found. Their offer: ssh-rsa
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

This error indicates that the SSH client cannot negotiate a matching host key type with the server. The server's offer of ssh-rsa is not accepted by the client, leading to connection failure.

Root Cause Analysis

The SSH protocol relies on asymmetric encryption algorithms for authentication and key exchange. Here, ssh-rsa refers to a signature scheme using RSA keys combined with the SHA-1 hash algorithm. However, SHA-1 has been proven vulnerable to collision attacks since 2017, with attack costs potentially under $50,000, rendering it insecure.

To address this threat, the OpenSSH project announced in its version 8.2 release (February 2020) that it would disable the ssh-rsa algorithm by default in future versions. This move aims to encourage users and service providers to migrate to safer alternatives, such as rsa-sha2-256 (RSA with SHA-256) or rsa-sha2-512 (RSA with SHA-512).

The issue arises because some Git hosting services (e.g., Azure DevOps) still only support ssh-rsa and have not upgraded to SHA-2 series algorithms. When users connect to these services with newer OpenSSH clients, the algorithm mismatch triggers the aforementioned error.

Temporary Solution

To temporarily restore SSH connectivity, you can re-enable the ssh-rsa algorithm by modifying the SSH client configuration. Follow these steps:

  1. Open or create the SSH client configuration file at ~/.ssh/config.
  2. Add the following configuration block, replacing your-azure-devops-domain with the actual domain (e.g., ssh.dev.azure.com):
Host your-azure-devops-domain
    User git
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa

This configuration uses the +ssh-rsa syntax to re-add the ssh-rsa algorithm to the list of acceptable algorithms, allowing the client and server to negotiate its use.

Security Risks and Long-term Recommendations

Although the above solution can temporarily resolve the issue, it is crucial to highlight its security risks:

Therefore, we strongly recommend the following long-term measures:

Conclusion

The Git SSH connection error "no matching host key type found. Their offer: ssh-rsa" stems from OpenSSH disabling the insecure SHA-1 algorithm while some services have not upgraded accordingly. Users can temporarily restore connectivity by modifying ~/.ssh/config, but must be aware of the security risks and actively adopt long-term solutions like HTTPS or migration to more secure platforms. Cybersecurity is an ongoing process, requiring collaboration between users and service providers to phase out weak algorithms and embrace modern encryption standards.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.