'ssh github works, but not git push.

I've never encountered ssh working and git not working in this way. Not sure how to troubleshoot.

ssh seems to work (-T prevents the first line):

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 seems to not work

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.

configs

My git config is

iam@heeere:/e/basic-computing-notes$ git config -l
[email protected]
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
[email protected]:bradyt/basic-computing-notes.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

My ssh config includes

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


Solution 1:[1]

I came across the same issue and I found out there was an entry in my .gitconfig which was replacing ssh with https.

[url "https"]
    insteadOf = git

I might have accidentally added this entry while using some tool. After removing this the problem was resolved.

Solution 2:[2]

Although this is not the answer to OP's question, I put this here for other people who might end up here like me:

When using a non-standard SSH port, the protocol needs to be explicitly specified, i.e.

git remote set-url origin git+ssh://git@host:port/url.git

instead of

git remote set-url origin git@host:port/url.git

Solution 3:[3]

I've had the same problem here when using 'https' protocol.

Git push doesn't work for 'https' protocol but if I manually change it to 'git' it works.

This doesn't work:

git push https://github.com/username/repo.git

But changing it to this works:

git push [email protected]:username/repo.git

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yusufali2205
Solution 2 Norman Pellet
Solution 3 William Baker Morrison