从调试日志来看,你的 SSH 客户端(OpenSSH 9.9)与腾讯云代码仓库的服务器协商密钥类型时失败,原因是服务器仅支持 ssh-rsa 类型的主机密钥,而你的客户端默认禁用了此算法(出于安全考虑)。以下是解决方案:
解决方案一:临时允许 ssh-rsa 密钥类型
在 Git 操作时,通过 -o 参数手动指定接受 ssh-rsa 密钥:
# 测试连接
ssh -Tv -o HostKeyAlgorithms=+ssh-rsa git@git.code.tencent.com
# 推送代码时强制使用(替换地址)
git push -c core.sshCommand="ssh -o HostKeyAlgorithms=+ssh-rsa" origin main
解决方案二:永久修改 SSH 配置
在 ~/.ssh/config
文件中为腾讯云代码仓库配置白名单:
# 编辑配置文件(Windows 路径为 C:\Users\用户名\.ssh\config)
nano ~/.ssh/config
添加以下内容:
~/.ssh/config
Host git.code.tencent.com
HostName git.code.tencent.com
User git
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
IdentityFile ~/.ssh/id_rsa # 可选:指定私钥路径
关键原因分析
现象 | 原因 | 解决方向 |
---|---|---|
no matching host key type found. Their offer: ssh-rsa | OpenSSH 9.8+ 默认禁用 ssh-rsa 密钥类型(因 SHA-1 安全隐患) | 客户端需显式启用 ssh-rsa |
补充说明
安全性提醒:ssh-rsa 密钥的安全性较弱,建议联系腾讯云代码仓库升级到更安全的密钥类型(如 ecdsa-sha2-nistp256 或 ssh-ed25519)。
验证配置生效:
ssh -T git@git.code.tencent.com # 成功后会提示 "Welcome to Tencent Code"
Windows 路径问题:若你使用 Windows,~/.ssh/config 对应路径为 C:\Users\你的用户名.ssh\config,需用记事本或 VS Code 编辑。