在 Azure DevOps 上使用 git 进行 Git SSH 公钥身份验证失败

标签 git azure-devops

我正在尝试将 git 存储库从 PowerShell 推送到 Azure DevOps 存储库,但在尝试推送时不断收到不同的身份验证错误。

我希望有人能够阐明我检查的内容,并进行适当的演练。

例如,

git remote add origin git@ssh.dev.azure.com:v3/MyAzure/MyProject/MyRepo
git push -u origin --all

我不断得到:

git@ssh.dev.azure.com's password:

我已经输入了各种密码,但仍然失败。它所说的密码是什么?

或者,我还得到了:

Permission denied, please try again.

fatal: Could not read from remote repository.

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

验证:

$ ssh -T myemail@mycompany.com
ssh: connect to host mycompany.com  port 22: Connection refused

我已完成以下操作:

  • 在 Azure DevOps 中创建了存储库
  • 根据 Microsoft 文档,使用 git-bash 创建 SSH key ,复制并粘贴到 Azure DevOps 安全性(不带空格)。
  • 转到我的个人资料/安全并添加 SSH key (在 git-bash 中生成)

我错过了显而易见的事情吗?使用个人访问 token 更好吗?谁能提供正确步骤的演练?

最佳答案

将这些行添加到 ~/.ssh/config 任何通配符条目之前:

Host ssh.dev.azure.com
  IdentityFile ~/.ssh/your_private_key
  IdentitiesOnly yes
  HostkeyAlgorithms +ssh-rsa
  PubkeyAcceptedKeyTypes=ssh-rsa

这个link通过@wcoder 帮助。此外,DevOps only allows deprecated ssh-rsa keys其中new versions of OpenSSH now block

最后,更荒谬的是,如果您有通配符条目(Host *),您将需要 exclude DevOps禁止使用该条目中的任何键,因为 DevOps will blindly accept the first key that the client provides 🤦🏻‍♂️:

Host * !ssh.dev.azure.com
    ...

关于在 Azure DevOps 上使用 git 进行 Git SSH 公钥身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52985167/

相关文章:

azure - 相当于发布管道的 YAML 是什么?

azure - 无法使用 Azure Bicep 和 Azure DevOps 管道部署 Azure 事件网格命名空间和主题

使用模板时Azure管道扩展每个参数

git - 如何删除分支中的特定提交

linux - ssh: 用户不允许 shell 不存在

powershell - 如何通过 tf.exe 从 Azure DevOps Agent 上的第二个项目获取文件?

azure-devops - VSTS - 有没有办法只在特定任务失败时运行任务?

git - IntelliJ IDEA - 'git pull' 命令的键盘快捷键是什么?

git - 如何从 bitbucket 中删除 git remote master?

git - 恢复到特定的 sha 或提交