ssh-github可以工作,但git-push不能。
我从未遇到过ssh和git不以这种方式工作的情况。不知道如何排除故障 ssh似乎可以工作(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
-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