简体   繁体   English

Gitlab-git clone在macOS中因ssh和https均失败

[英]Gitlab - git clone failed both with ssh and https in macOS

My coworker grant me access to his repository as Master, then i clone it both with SSH and HTTPS, but it always failed : 我的同事授予我以管理员身份访问其存储库的权限,然后我同时使用SSH和HTTPS对其进行了克隆,但始终失败:

GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.

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

i've been check my generated public key in .pub file and already inserted to my Gitlab account. 我已经检查过我在.pub文件中生成的公钥,并且已经插入到我的Gitlab帐户中。 and i'm also tried to clone a repository(from other owner), and it works! 而且我还试图克隆一个存储库(从其他所有者那里),并且可以正常工作! it's confusing. 令人困惑。

have i missed something? 我错过了什么吗?

I had the same problem and I found multiple issues. 我遇到了同样的问题,并且发现了多个问题。 I am not an expert in this area, but here is a summary of the steps I took to resolve. 我不是该领域的专家,但是这里是我要解决的步骤的摘要。 Hopefully it will be helpful: 希望它将对您有所帮助:

Solving the HTTPS clone problem: 解决HTTPS克隆问题:

  1. Clone was failing with the error above, and I was not being prompted for my username and password on the command line. 克隆失败并出现上述错误,并且在命令行中未提示我输入用户名和密码。 Running clone with verbose flag 使用详细标志运行克隆

    git clone --progress --verbose https://[my_gitlab_server]/[repo]/[project].git

    showed git was pulling credentials from OSX Toolchain, which were apparently incorrect. 显示git从OSX Toolchain中提取凭证,这显然是不正确的。 I disabled this using instructions here . 我使用此处的说明禁用了此功能。

    sudo git config --system --unset credential.helper

  2. I was now getting username and password prompt, but got: 我现在收到用户名和密码提示,但得到:

    remote: HTTP Basic: Access denied remote: You must use a personal access token with 'api' scope for Git over HTTP. 远程:HTTP基本:访问被拒绝远程:您必须对HTTP上的Git使用具有“ api”范围的个人访问令牌。 remote: You can generate one at https://[my_gitlab_server]/profile/personal_access_tokens fatal: Authentication failed for ' https://[my_gitlab_server]/[repo]/[project].git/ ' 远程:您可以在https:// [my_gitlab_server] / profile / personal_access_tokens生成一个。致命:' https:// [my_gitlab_server] / [repo] / [project] .git /的身份验证失败

    So I created a Personal Access Token as instructed here . 因此,我按照此处的指示创建了个人访问令牌。

  3. I was not sure what to do with the token. 我不确定该如何处理令牌。 Turns out you can include it in the URL as described here (for me that looked like git clone https://oauth2:[token]@[my_gitlab_server]/[project].git ) or you can just paste the token at the command line prompt for 'password'. 原来,您可以按此处描述的那样将其包括在URL中(对我来说,它看起来像git clone https://oauth2:[token]@[my_gitlab_server]/[project].git ),也可以仅将令牌粘贴到命令中提示输入“密码”。

I could now clone via HTTPS. 我现在可以通过HTTPS进行克隆。

Solving the SSH clone problem: 解决SSH克隆问题:

The SSH clone was giving the same error as the HTTPS clone. SSH克隆出现与HTTPS克隆相同的错误。 Some background on bash agents is helpful here. 一些有关bash代理的背景在这里很有帮助。

  1. I found my ~/.ssh/config file in my user directory and verified the repo had an entry there. 我在用户目录中找到了〜/ .ssh / config文件,并验证了存储库中是否有条目。

    Host [my_gitlab_server]/[repo] IdentityFile ~/.ssh/id_rsa2

  2. I had multiple id-rsa files in the ssh directory, so I opened id_rsa2.pub (the one associated with my repo in the config file) and compared it to the key I found in my repo by navigating to the 'SSH Keys' tab in my 'Profile Settings'. 我在ssh目录中有多个id-rsa文件,因此我打开了id_rsa2.pub (与配置文件中与我的回购关联的那个),并通过导航到“ SSH密钥”选项卡将其与我的回购中找到的密钥进行了比较。在我的“个人资料设置”中。 The keys were the same. 按键是相同的。

    (If you need help creating and viewing keys see the docs here .) (如果您需要创建和查看密钥的帮助,请参阅此处的文档。)

My keys were in place, but my SSH clone was still not working. 我的密钥已经安装到位,但是我的SSH克隆仍然无法正常工作。

  1. I thought there might be a problem with the config file or that my keys were no longer valid, so I bypassed the config file by manually adding the key to the current terminal session using instructions here . 我认为配置文件可能有问题,或者我的密钥不再有效,因此我通过使用此处的说明将密钥手动添加到当前终端会话中,从而绕过了配置文件。

    eval $(ssh-agent -s) ssh-add ~/.ssh/id_rsa2

    This worked so I knew my key was valid. 这行得通,所以我知道我的钥匙是有效的。

    (By the way, to see the keys loaded into your agent run ssh-add -L and to see their fingerprints run ssh-add -l .) (顺便说一句,要查看加载到代理中的密钥,请运行ssh-add -L并查看其指纹运行ssh-add -l 。)

The problem now was that I needed to use the ~/.ssh/config file so I would not have to run eval and ssh-add every time I opened a new terminal window. 现在的问题是,我需要使用〜/ .ssh / config文件,因此不必在每次打开新的终端窗口时都运行evalssh-add

  1. To troubleshoot I ran ssh -Tvv git@[my_gitlab_server] which successfully connected to my gitlab server, but using a key I didn't recognize. 为了排除故障,我运行了ssh -Tvv git@[my_gitlab_server] ,它已成功连接到我的gitlab服务器,但是使用了我不认识的密钥。 In the output I noticed that the file id-rsa2 was not searched. 在输出中,我注意到未搜索文件id-rsa2
  2. Using information from ssh.com about keys and ssh_config files , I found the the /etc/private/ssh/ssh_config file specifies which keys are used. 使用ssh.com上有关密钥ssh_config文件的信息 ,我发现/ etc / private / ssh / ssh_config文件指定了要使用的密钥。 The defaults were: 默认值为:

    IdentityFile ~/.ssh/id_rsa IdentityFile ~/.ssh/id_dsa IdentityFile ~/.ssh/id_ecdsa IdentityFile ~/.ssh/id_ed25519

    I added my id_rsa2 key by running sudo nano /private/etc/ssh/ssh_config and adding this line: 我通过运行sudo nano /private/etc/ssh/ssh_config并添加以下行来添加id_rsa2密钥:

    IdentityFile ~/.ssh/id_rsa2

This worked like a champ. 这就像冠军。

Overall its better to use a single ssh key with the default id_rsa name to avoid problems like this. 总体而言,最好使用单个带有默认id_rsa名称的ssh密钥来避免此类问题。

Okay, Could yo check your git globals are correct respect your GitLab account. 好的,请检查您的git globals是否正确,尊重您的GitLab帐户。

$ git config --global user.name "Your name"
$ git config --global user.email your@mail.com

I got some problems cloning when my data was wrong. 数据错误时克隆时遇到一些问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM