jay shah
jay shah

Reputation: 993

Different git config user and ssh keys, how do I make git pull work?

Does bitbucket ssh keys and git config user have any relation with each other?

When I try ssh -T [email protected],

It gives a different user than when I try git config -l for the current git repo.

How does ssh authentication for git work?

Also I am not sure the ssh keys present in my .ssh folder are of which user?

I am not able to authenticate to bitbucket for access to the current git repo.

How do I fix this?

Upvotes: 1

Views: 1422

Answers (1)

Jim Redmond
Jim Redmond

Reputation: 5631

Git config is not relevant to SSH authentication (or HTTP/HTTPS authentication) - it's only relevant to Git's internal tracking of commits. Similarly, SSH authentication is only relevant to the systems on either end of the SSH (in this case, your system and Bitbucket), and HTTP/HTTPS authentication is only relevant to HTTP/HTTPS authentication. It doesn't really matter if the SSH user and .git/config user don't match; Git will do its thing, and it will run the SSH commands (with SSH's own configs) when the time comes.

The ssh -T [email protected] check you performed shows which Bitbucket user has the relevant key added. (You can see which specific key it's using with ssh -Tv [email protected].) If you're unable to work on a particular Bitbucket repo using SSH, but you get a username back from ssh -T [email protected], then one or more things may be going on here:

  • Your Bitbucket user doesn't have the relevant permission to that repo.
  • You're trying to push to a branch that has branch permissions specified, and you don't have permission to do what you're trying to do.
  • That key has been added to Bitbucket as an "access key" - a read-only key for CI/CD systems to use to get to a given repo - and you're either trying to push or trying to use that key on a repo where it doesn't have access.
  • There's another issue that you aren't mentioning here - perhaps your local copy of the repo is a few commits behind what Bitbucket has, or your local copy is corrupted on-disk, or your local SSH client is not functioning properly.

The specific message you get back should indicate which of those potential problems may be the one. (You didn't really get into enough detail for us to tell.)

With Bitbucket specifically, you can also put the Bitbucket username as part of the SSH URL in the remote - something like git clone [email protected]:owner/repo, or git remote set-url origin [email protected]:owner/repo. This is mostly so that people who work on multiple Bitbucket accounts from the same system can keep their SSH keys distinct. ([email protected] still works, of course, as does the ~/.ssh/config hack, but I think the username-specific approach is a little cleaner.)

Upvotes: 2

Related Questions