0

I have several SSH keys:

~/.ssh/
    id_rsa
    id_rsa.pub
    fizz
    fizz.pub
    buzz
    buzz.pub

I cloned a GitHub project using HTTPS (e.g. git clone https://github.com/someorg/somerepo.git). I made some changes and now I'm trying to push them, however I'm getting the famous error:

"Permission to someorg/somerepo.git denied to blah-user"

Where blah-user is (I believe) the user associated with my id_rsa SSH key. So I think git is defaulting to use my id_rsa key, whereas I would like to specifically user the buzz key for making the push (I've associated that buzz key with my GitHub account).

Any ideas as to what I could do here, or what I can do to specifically use the buzz key as part of my push?

1 Answer 1

4

Since you cloned the https url git will try to use https when pushing to your remote. HTTP(S) and SSH are different protocols and use different credentials so it will in fact not look at your ssh-keys at all.

Git will probably ask for your http-credentials on the prompt or you can use a 'git-credential-store' helper to keep them on file https://git-scm.com/docs/git-credential-store

If you clone using the ssh protocol git will delegate the authentication to SSH which will look for a private key in the .ssh directory.

You can define which key in many ways, I prefer to set up a .ssh/config file with an entry for the host I'm connecting to.

Host thehost.com
    Hostname thehost.com
    IdentityFile ~/.ssh/my_github_key_id_rsa
    User mu-username
Sign up to request clarification or add additional context in comments.

2 Comments

OK thanks (and +1), so it sounds like you're saying that since I cloned via HTTPS that its not looking at my SSH keys at all. If that's true, then in my error message Permission to someorg/somerepo.git denied to blah-user, where is git getting blah-user from? I thought it was getting that user from my id_rsa SSH key somehow, but you're saying that's not the case. If I can figure out where blah-user is coming from I can probably get this fixed. Thanks again!
I don't know where it gets it from but two placess you can check: it could be either in the remote URL - like 'username@host/repo.git' or it can be the git configuration 'git config --get-all user.name'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.