我从来没有遇到过ssh工作而且git没有以这种方式工作。不确定如何排除故障。
ssh似乎有效(-T
阻止了第一行):
iam@heeere:/e/.ssh$ ssh github
PTY allocation request failed on channel 0
Hi bradyt! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
git push似乎不起作用
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"
答案 0 :(得分:3)
由于您的ssh密钥没有默认名称(id_rsa
,id_rsa.pub
),您需要使用您定义的ssh配置条目,以便您的ssh网址引用正确的密钥:< / p>
git remote set-url origin github:bradyt/basic-computing-notes.git
这样,ssh会查找~/.ssh/github_rsa
,而不是查找~/.ssh/id_rsa
。
更简单,musiKk建议in the comments,将ssh配置的条目更改为github.com
。
Host github.com github
HostName github.com
User git
IdentityFile "~/.ssh/github_rsa"
我保留Hostname
和User
只是为了确定,但默认网址会有效(git@github.com:bradyt/basic-computing-notes.git
)
由于raphinesse提及in the comments:
如果您仍想使用快捷方式
github
,Host
关键字可以使用多种模式。
来自ssh_config
man page:如果提供了多个 pattern ,则应使用空格分隔。
答案 1 :(得分:1)
我遇到了同样的问题,我发现我的.gitconfig中有一个条目正在用https替换ssh。
[url "https"]
insteadOf = git
我可能在使用某些工具时意外添加了此条目。删除后,问题得到解决。
答案 2 :(得分:0)
虽然这不是 OP 问题的答案,但我把它放在这里是为了其他可能像我一样最终来到这里的人:
使用非标准SSH端口时,需要明确指定协议,即
git remote set-url origin git+ssh://git@host:port/url.git
代替
git remote set-url origin git@host:port/url.git