我正在尝试使用SSH克隆git存储库。因此,我在本地计算机上创建了一个ssh密钥对,并在git repo(Bitbucket服务器)上添加了公共(public)密钥。

然后,正如我看到的here一样,我尝试像这样进行克隆:

git clone ssh://my_username@my-repository.com:7999/my_project.git

git clone ssh://git@my-repository.com:7999/my_project.git

这些选项不起作用:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

我唯一取得的进步就是尝试了这一点:
git clone my_username@my-repository.com:7999/my_project.git

这要求我输入密码3次,然后失败。我怀疑这虽然不使用SSH,
因为我认为SSH不应要求输入密码。
Password:
Password:
Password:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,keyboard-interactive).
fatal: Could not read from remote repository.

那么,如何使用SSH克隆git repo?

编辑

我在Windows上,并且正在使用Git Bash。
ssh-add -l

退货
The agent has no identities.

最佳答案

大多数服务器都希望用户使用“git”用户名以及用于识别目的的自己的私钥进行身份验证。

只需尝试使用SSH连接:

ssh ${USERNAME}@${SERVER} -p ${PORT}

这将确定您是否甚至可以针对服务器进行身份验证,从而从等式中删除git。

您的私钥在哪里?如果不是~/.ssh/id_rsa(或配置的路径),则需要提供它的路径。试试这个:

ssh ${USERNAME}@${SERVER} -p ${PORT} -i ${MY_PRIVATE_KEY}

如果可行,则可以将SSH配置设置为更加方便。
~/.ssh/config中,您可以输入以下内容:
Host ${FRIENDLY_NAME}
    User ${USERNAME}
    Hostname ${SERVER}
    Port ${PORT}
    IdentityFile ${MY_PRIVATE_KEY}

然后,您可以像这样测试连接:
ssh ${FRIENDLY_NAME}

最后:
git clone ssh://${FRIENDLY_NAME}/${REPO_PATH}

如果不是默认端口(22),则只需指定端口。

注意:我使用了波浪号(~),因为您在编写答案时没有指定Windows。您可以在Windows上按Win + R,输入点.,然后按回车键来查找“主”目录。通常,这将带您到C:\Users\%USERNAME%

07-24 12:52
查看更多