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-push不能。_Git_Github_Ssh - Fatal编程技术网

ssh-github可以工作,但git-push不能。

ssh-github可以工作,但git-push不能。,git,github,ssh,Git,Github,Ssh,我从未遇到过ssh和git不以这种方式工作的情况。不知道如何排除故障 ssh似乎可以工作(-T阻止第一行): git推送似乎不起作用 iam@heeere:/e/basic-computing-notes$ git push Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the

我从未遇到过ssh和git不以这种方式工作的情况。不知道如何排除故障

ssh似乎可以工作(
-T
阻止第一行):

git推送似乎不起作用

iam@heeere:/e/basic-computing-notes$ git push
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
配置 我的git配置是

iam@heeere:/e/basic-computing-notes$ git config -l
user.email=algebrat@uw.edu
user.name=Brady Trainor
push.default=simple
alias.ac=!git add --all && git commit
alias.lol=log --oneline --graph --decorate --all
core.editor=vim
core.excludesfile=/e/configs/.gitignore_global
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:bradyt/basic-computing-notes.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
我的ssh配置包括

Host github
  HostName github.com
  User git
  IdentityFile "~/.ssh/github_rsa"

由于您的ssh密钥没有默认名称(
id\u rsa
id\u rsa.pub
),您需要使用您定义的ssh配置条目,以便您的ssh url引用正确的密钥:

git remote set-url origin github:bradyt/basic-computing-notes.git
这样,ssh将查找
~/.ssh/github\u rsa
,而不是查找
~/.ssh/id\u rsa


建议将ssh配置的条目更改为
github.com
,这样更简单

Host github.com github
  HostName github.com
  User git
  IdentityFile "~/.ssh/github_rsa"
我保留了
主机名
用户
,只是为了确保这一点,但是默认的url会起作用(
git@github.com:bradyt/basic computing notes.git

如前所述:


如果您仍要使用快捷方式
github
,则
Host
关键字允许使用多种模式。
从:

如果提供了多个,则应使用空格分隔


我遇到了同样的问题,我发现在我的.gitconfig中有一个条目正在用https替换ssh

[url "https"]
    insteadOf = git

我可能在使用某些工具时意外添加了此条目。删除此选项后,问题得到解决。

或者,将配置的第一行设置为
主机github.com
。那么您就不需要
HostName
User
指令了。@musiKk说得对。我已将其包含在答案中,以提高可见性。@VonC真棒。我发现偏离“标准的做事方式”通常会导致痛苦。你做的假设越少越好。替代解决方案只需要一次修改,而不是两次修改。如果您仍然希望使用快捷方式
github
,则
Host
关键字允许使用多个模式。从
ssh\u config
手册页:如果提供了多个模式,则应使用whitespace@raphinesse谢谢,说得好。我已将您的评论包含在答案中,以提高可视性。
[url "https"]
    insteadOf = git