首先我从远程GitHub上面git clone 项目是没问题的,在此之前各种ssh文件以及远程公钥都是配置过的。
在本地修改项目内容,想要上传至远程,我们一般都是使用如下三个命令:
// 添加当前目录的所有文件到暂存区
git add .
// 或者 添加指定文件到暂存区
git add <filename>
// 提交暂存区到仓库区
git commt -m "你的描述"
//上传本地指定分支到远程仓库
git push -u origin master
但是我到git push 那一步就出问题了,由于这不是我第一次碰到这个问题,所以这次记录下。
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我首先进行了测试:输入
ssh -T git@github.com
然后输出是正常的
Hi Mrhuangyi! You've successfully authenticated, but GitHub does not provide shell access.
其实这也说明了我本地公钥是存在且没有什么问题的
看本地的.git/config设置的仓库url地址和github使用的链接地址是否一致,如果不一致,说明你这里有问题
cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = git@github.com:Mrhuangyi/xiaochengxu.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
解决方案
把你的公钥放到系统里面
ssh-add ~/.ssh/id_rsa
Enter passphrase for /Users/a/.ssh/id_rsa:
Identity added: /Users/a/.ssh/id_rsa (/Users/a/.ssh/id_rsa)
之后再尝试git push 应该就没什么问题了。