Ssh github works, but not git push.

I've never encountered ssh working and git didn't work that way. Not sure how to troubleshoot.

ssh works ( -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 doesn't seem to 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

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"

      

+3


source to share


2 answers


Since your ssh keys do not have a default name ( id_rsa

, id_rsa.pub

), you need to use the ssh config entry you entered so that your ssh url will refer to the correct keys:

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

      

This way ssh will search ~/.ssh/github_rsa

instead of searching ~/.ssh/id_rsa

.


Simplified, musiKk suggests in the comments by changing the ssh config entry to github.com

.



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

      

I just saved Hostname

and User

, but the default url ( git@github.com:bradyt/basic-computing-notes.git

) will work instead

As raphinesse mentions in the comments :

If you still want to use a shortcut github

, the keyword Host

allows multiple templates.
From the ssh_config

man page
:

If more than one pattern is provided , they must be separated by spaces.

+3


source


I faced the same problem and I found that there was an entry in my .gitconfig that replaces ssh with https.

[url "https"]
    insteadOf = git

      



I may have accidentally added this entry using some tool. After fixing the problem, the problem was resolved.

+1


source







All Articles