【问题标题】:Could not read from remote repository with SSH无法使用 SSH 从远程存储库中读取
【发布时间】:2020-10-31 16:51:43
【问题描述】:

我已完成所有步骤,但无法连接到远程存储库。

我将 ssh 密钥添加到我的 GitLab 帐户,但出现错误:

user@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

完整输出:

user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ ssh-keygen -t rsa -b 4096 -C "email@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/user/.ssh/id_rsa):
Created directory '/c/Users/user/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/user/.ssh/id_rsa
Your public key has been saved in /c/Users/user/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:xxxx email@gmail.com
The key's randomart image is:
+---[RSA 4096]----+
...
+----[SHA256]-----+

user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ git push origin master
The authenticity of host 'gitlab.com (...)' can't be established.
ECDSA key fingerprint is SHA256:....
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.com,...' (ECDSA) to the list of known hosts.
user@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ git remote get-url
usage: git remote get-url [--push] [--all] <name>

    --push                query push URLs rather than fetch URLs
    --all                 return all URLs


user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ git remote get-url origin
ssh://gitlab.com/myaccount/instabot.git

user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ eval `ssh-agent -s`
Agent pid 1189

【问题讨论】:

    标签: git ssh gitlab


    【解决方案1】:
    user@gitlab.com: Permission denied (publickey).
    

    尝试将 SSH URL 更改为:

    cd /path/to/repo
    git remote set-url origin git@gitlab.com:myaccount/instabot.git
    

    请注意,SSH 用户应始终为“git@”,而不是“user@”

    【讨论】:

    • 谢谢,如果我在这个 git@gitlab.com 之前添加 ssh:// 就可以了
    • @toioioi 是的,抱歉打错了:git@gitlab.com:myaccount/instabot.gitssh://git@gitlab.com/myaccount/instabot.git。请注意一种情况下的“:”,另一种情况下的“/”。
    猜你喜欢
    • 2019-11-02
    • 2013-04-13
    • 2013-03-14
    • 2018-12-10
    • 2019-01-03
    • 2014-11-25
    • 2020-11-03
    • 2016-09-07
    • 1970-01-01
    相关资源
    最近更新 更多