Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights

时间:2023-03-08 22:30:48

Permission denied (publickey). fatal: Could not read from remote repository.  Please make sure you have the correct access rights

第一次提交遇到这样的情况,怎么回事呢,我在github上提交了ssh key 的啊。

排查先看看能不能解析,

1.先 ping https://github.com

把ip添加到 host :    sudo vi /etc/hosts  (添加下面第三行)

127.0.0.1  localhost  localhost.localdomain  VM-0-6-ubuntu
127.0.1.1 TENCENT
192.30.255.113  github.com # 添加ip # The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.30.255.113 github.com
~

2.如果不行的话看看自己有没有输入错误的创库地址

查看配置

cat .git/config

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@github:cuzz1/flask.git # 错误的
url = git@github.com:cuzz1/flask.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master

3. 现在提交还出现

Permission denied (publickey). fatal: Could not read from remote repository.  Please make sure you have the correct access rights

那就是github 上的ssh key 添加错了,我们用ssh-keygen -t rsa -C "xxxx@163.com" 会生成在很多目录下,比如root/.ssh、 /home/ubuntu/.ssh 都有ras_id.pub

所以我们不能添加错了。必须在 ~/.ssh目录下  才有用,要是当前目录,把  ~/.ssh/ras_id.pub 拷到github上就可以了。

现在提交就可以了。

Permission denied (publickey). fatal: Could not read from remote repository.  Please make sure you have the correct access rights

感谢军哥的帮忙 ,微信公众号 Python之禅