使用SSH克隆git repo

时间:2017-03-16 16:43:47

标签: git ssh

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

然后,正如我看到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.

3 个答案:

答案 0 :(得分:0)

您确定此主机上的ssh是否适用于端口7990?如果这个repo是在bitbucket上,那么我几乎可以肯定你使用ssh的默认端口

git clone my_username@my-repository.com/my_project.git

就像git with bitbucket

一样

答案 1 :(得分:0)

大多数服务器都希望用户使用' 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%

答案 2 :(得分:0)

您需要检查您的公钥权限。您的访问权限因特权而被拒绝。

这将解决您的问题。

chmod 700 /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
相关问题