Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解决远程SSH推送github错误_Git_Github_Ssh_Remote Repository - Fatal编程技术网

如何解决远程SSH推送github错误

如何解决远程SSH推送github错误,git,github,ssh,remote-repository,Git,Github,Ssh,Remote Repository,我已经创建了链接到github的SSH密钥。我正在尝试将文件远程推送到创建的存储库 这是我的密码 git init git add README.md git commit -m "first commit" git branch -M main git remote add origin https://github.com/username/demo_repo2.git git push -u origin main 但它给我的错误是: git@github.com:权

我已经创建了链接到github的SSH密钥。我正在尝试将文件远程推送到创建的存储库

这是我的密码

git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/username/demo_repo2.git
git push -u origin main
但它给我的错误是:

git@github.com:权限被拒绝(公钥)。 致命:无法从远程存储库读取

请确保您拥有正确的访问权限 并且存储库存在

我已经检查了ssh密钥是否链接,并且它是。它甚至在给予

git remote -v

origin  git@github.com:user/repo2.git (fetch)
origin  git@github.com:user/repo2.git (push)

我尝试了几乎所有的答案,但没有成功。请有人帮助我

由于您已将HTTPS URL设置为:

git remote add origin https://github.com/username/demo_repo2.git
cd /path/to/my/repo
git remote set-url  origin https://github.com/username/demo_repo2.git
检查
git config-l
以查看任何
url。“git@github.com:“。代替https://github.com/
指令

如果
git remote-v
确实给了您一个SSH URL,这意味着第一个
git remote add origin
必须失败。
您可以使用以下命令强制HTTPS URL:

git remote add origin https://github.com/username/demo_repo2.git
cd /path/to/my/repo
git remote set-url  origin https://github.com/username/demo_repo2.git

您已经创建了ssh密钥并将公钥链接到您的github帐户,这需要首先完成

然后,您需要将RSA密钥添加到ssh代理并执行身份验证命令,以测试您的密钥是否已与github同步。这些可以通过以下命令来完成。(在将公钥添加到github之后)

eval“$(ssh代理-s)”//评估进程ID
ssh add ~/.ssh///将密钥添加到代理

ssh-Tgit@github.com
试试这个。还有删除.ssh/known_hosts文件请详细解释您到底尝试了什么?我尝试过,但在第二个命令中,无法从目录中识别ssh密钥在第二个命令中,您应该添加私钥,而不是公钥(即.pub)