有人看到这个错误并知道该怎么做吗?

我正在使用终端,我在根,GitHub存储库存在,我不知道现在该做什么。

> git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

当前回答

我在远程主机上使用git pull寻找类似错误消息的解决方案时发现了这个页面:

$ git pull
Permission denied (publickey).
fatal: Could not read from remote repository.

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

我通过ssh -AY remote_hostname从本地计算机连接到远程主机。这不是OP问题的解决方案,但对其他遇到这个页面的人很有用,所以把它贴在这里。

注意,在我的例子中,git pull在我的本地机器上工作良好(也就是说,ssh密钥已经设置,并添加到GitHub帐户等)。我通过将这个添加到~/来解决我的问题。Ssh /config在我的笔记本电脑:

Host *
     ForwardAgent yes

然后我用ssh -AY remote_hostname重新连接到远程主机,git拉现在工作了。配置中的更改允许将我的ssh对从本地计算机转发到任何主机。ssh的-A选项实际上是在ssh会话中转发它。点击这里查看更多细节。

其他回答

设置SSH访问GitHub的完整步骤已经发布在ServerFault上。

查看来自@Alex的答案:https://serverfault.com/a/1088209/416091

在2022年7月24日,我应该在SSH用户配置文件(~/. SSH /config)中将服务器和端口设置为SSH .github.com:443。

我想我有最好的答案给你,你的git应用程序读取你的id_rsa。根用户目录下的Pub

/home/root/.ssh/id_rsa.pub

这就是为什么你的密钥在/home/your_username/.ssh/id_rsa中。少年犯看不懂酒吧。因此,您需要在/home/root/.ssh/中创建密钥

$ sudo su
$ ssh-keygen
$ cd ~/.ssh
$ cat id_rsa.pub

然后复制密钥在你的github帐户。 这对我很有效。你可以试试。

这对我很有用

有2个选项在github - HTTPS/SSH

我错误地选择了SSH,因此出现了错误-_-

切换到HTTPS,然后复制url再次尝试:)

你需要生成一个SSH密钥(如果你没有的话),并将公钥与你的Github帐户相关联。参见Github自己的文档。

同样在ubuntu中,即使在BitBucket的设置中已经输入了SSH密钥,我还是遇到了这个问题。原因是,我尝试了以下几点:

sudo git push origin master

不知道为什么,但它解决了使用

git push origin master

没有使用sudo。