首页 > 解决方案 > 如何从 Bitbucket 存储库推送到 Azure 存储库,不同的用户电子邮件

问题描述

我在Bitbucket的一个分支中有一些代码,我需要将它们推送到Azure中类似 repo 中的一个分支。我只能使用不同的电子邮件访问这两个存储库。我已经在 Azure 中克隆了新的 repo 并在我的本地设置了 ssh 密钥。由于我必须使用不同的电子邮件,因此两个存储库的 ssh 密钥是不同的,对吗?不确定是否可以建立连接。

我在我的 Bitbucket 存储库中。这是我所做的和错误消息:

> git remote -v
origin  git@bitbucket.org:<repo in Bitbucket> (fetch)
origin  git@bitbucket.org:<repo in Bitbucket> (push)

> git remote set-url origin git@ssh.dev.azure.com:<repo in Azure>

> git remote -v
origin  git@ssh.dev.azure.com:<repo in Azure> (fetch)
origin  git@ssh.dev.azure.com:<repo in Azure> (push)

> git config user.email <my email in Azure>

> git fetch
    
The authenticity of host 'ssh.dev.azure.com (xx.xx.xx.xxx)' can't be established.
RSA key fingerprint is SHAxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ssh.dev.azure.com,xx.xx.xx.xxx' (RSA) to the list of known hosts.
remote: Public key authentication failed.
fatal: Could not read from remote repository.

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

更新 08/21

这个链接有帮助。

基本上编辑~/.ssh/config并添加以下内容:

Host ssh.dev.azure.com
IdentityFile ~/.ssh/my_ssh_private_key
IdentitiesOnly yes

标签: gitssh

解决方案


git config user.email身份验证无关。

SSH 将默认使用~/.ssh/id_rsa私钥,您可能需要为 Azure 使用专用私钥,这与您用于 BitBucket 的私钥不同。

所以这会起作用:

export GIT_SSH_COMMAND='ssh -i ~/.ssh/azure_private_key'
git fetch

或者

git -c 'core.sshCommand="ssh -i ~/.ssh/azure_private_key"' fetch

将“ azure_private_key”替换为您的 Azure 私钥。


推荐阅读