Git:公钥认证失败

bra*_*vdk 6 git azure-devops

当我想在azure devops(vsts)上使用git时,我不能使用git clone,pull,push等。出现错误:

remote:remote:您的Git命令未成功。remote:详细信息:remote:公钥身份验证失败。remote:致命:无法从远程存储库读取。

但是当我使用下面的命令时,它起作用了,所以问题不是关键。 ssh-agent sh -c 'ssh-add ~/.ssh/key; git push repo'

当我执行git clone,push,pull等时,我认为它会通过您的.ssh目录自动检查要使用的密钥。有人对如何解决这个问题有任何想法吗?

小智 11

我在 ~/.ssh/config 中添加:

Host ssh.dev.azure.com
  IdentityFile ~/.ssh/[you private key file]
Run Code Online (Sandbox Code Playgroud)


bra*_*vdk 10

通过创建〜/ .ssh / config并添加来修复它:

Host xxx.visualstudio.com
  IdentityFile ~/.ssh/key
Run Code Online (Sandbox Code Playgroud)

确保执行chmod 0400〜/ .ssh / config

  • 查看官方文档 [我有多个 SSH 密钥。如何对不同的 SSH 服务器或存储库使用不同的 SSH 密钥?](https://docs.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view= azure-devops&tabs=current-page#qi-have-multiple-ssh-keys--how-do-i-use- different-ssh-keys-for- different-ssh-servers-or-repos) (3认同)

Yur*_*iak 5

我的情况比较棘手。VisualStudio.com 禁止了我的旧 ssh 密钥,并且没有费心以某种方式通知我。经过实验,我发现我只需要添加一个新密钥并使用即可。

ssh-keygen -f ~/.ssh/new_key
Run Code Online (Sandbox Code Playgroud)

在~/.ssh/config中:

Host vs-ssh.visualstudio.com
  IdentityFile ~/.ssh/new_key
Run Code Online (Sandbox Code Playgroud)

那行得通。有趣的是,他们不允许您从SSH Keys页面中删除旧的禁用密钥。

更新:对于默认生成 ssh-rsa 密钥的OpenSSH 8.9p1ssh-rsa ,您可能需要在 ssh_config 或 ~/.ssh/config 中启用。

    PubkeyAcceptedAlgorithms +ssh-rsa
    HostkeyAlgorithms +ssh-rsa
Run Code Online (Sandbox Code Playgroud)

请参阅/sf/answers/5047168731/


Gui*_*n70 5

我通过将身份添加到 SSH 提供商来解决了这个问题

ssh-add [path to your private key]

所以,例如:

ssh-add /home/myuser/.ssh/id_rsa