4

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
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

My ssh config includes

Host github
  HostName github.com
  User git
  IdentityFile "~/.ssh/github_rsa"
Brady Trainor
  • 2,026
  • 20
  • 18
  • You could find the answer here: https://stackoverflow.com/questions/57734669/gitgithub-com-permission-denied-publickey https://stackoverflow.com/questions/12940626/github-error-message-permission-denied-publickey – Xab Ion Feb 17 '22 at 05:57

4 Answers4

7

Since your ssh keys has not the default name (id_rsa, id_rsa.pub), you need to use the ssh config entry you defined, in order for your ssh url to reference the right keys:

git remote set-url origin github:bradyt/basic-computing-notes.git

That way, ssh will look for ~/.ssh/github_rsa, instead of looking for ~/.ssh/id_rsa.


Simpler, musiKk suggests in the comments, changing the entry of the ssh config to github.com.

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

I have kept the Hostname and User just to be sure, but the default url would then work (git@github.com:bradyt/basic-computing-notes.git)

As raphinesse mentions in the comments:

In case you still want to use the shortcut github, the Host keyword allows for multiple patterns.
From the ssh_config man page:

If more than one pattern is provided, they should be separated by whitespace.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Or, alternatively make the first line of your config `Host github.com`. You wouldn't need the `HostName` and `User` directives then. – musiKk Oct 14 '14 at 07:49
  • @musiKk good point. I have included it in the answer for more visibility. – VonC Oct 14 '14 at 07:53
  • @VonC Awesome. I find deviating from "the standard way of doing things" usually causes pain down the line. The fewer assumptions you have to make, the better. The alternative solution only requires one modification instead of two. – musiKk Oct 14 '14 at 07:56
  • In case you still want to use the shortcut `github`, the `Host` keyword allows for multiple patterns. From the `ssh_config` man page: *If more than one pattern is provided, they should be separated by whitespace* – raphinesse Dec 01 '15 at 19:21
  • @raphinesse Thank you, good point. I have included your comment in the answer for more visibility. – VonC Dec 01 '15 at 20:37
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.

Yusufali2205
  • 1,222
  • 9
  • 17
0

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

Norman Pellet
  • 374
  • 2
  • 9
0

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 git@github.com:username/repo.git

William Baker Morrison
  • 1,642
  • 4
  • 21
  • 33
Ian Andwati
  • 333
  • 2
  • 9