4

I have to keys in ~/.ssh dir. When I am trying to commit something in console bitbucket is asking me for password instead use ssh key. Also when I try to clone this repo in order to use global git settings it is still asking me for password.

My questions:

  • how to config git to use ssh keys?
  • how to force it?
  • which key it is trying to use?
  • is it trying to much it by email? (if yes than is it using mail from global config or local repository config?)
  • can I use ssh key without additional password, or is it required to have one?
luator
  • 4,769
  • 3
  • 30
  • 51
gkucmierz
  • 1,055
  • 1
  • 9
  • 26
  • Is the key added to your `ssh-agent` as per https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#adding-your-ssh-key-to-the-ssh-agent ? Is the public key added to your BitBucket account? –  Dec 29 '16 at 18:32
  • Well, it sounds like you have a passphrase on the key. That will be required every time you use that key pair. –  Dec 29 '16 at 19:09
  • No! Bitbucket is asking me for its password. – gkucmierz Dec 29 '16 at 19:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/131834/discussion-between-gkucmierz-and-jack-maney). – gkucmierz Dec 29 '16 at 19:21
  • If you happen to be on a Mac that you recently updated to Sierra, you should look at [this question](http://stackoverflow.com/questions/41287226/ssh-asking-every-single-time-for-passphrase/41287392#comment69777996_41287392). – Dan Lowe Dec 29 '16 at 23:55

2 Answers2

10

To make GIT use a specific SSH key, you prefix the GIT command with

GIT_SSH_COMMAND="ssh -i <path-to-key>"

Where "path-to-key" is the path to the private SSH key (without the ".pub").

So if you would like to clone from git://random-address and your public key is in /home/me/.ssh/mysecondkey.pub, you run:

GIT_SSH_COMMAND="ssh -i /home/me/.ssh/mysecondkey" git clone git://random-address

You need to make sure that you choose a clone-URL which does not start with "https://", but either "ssh://" or "git://". I know at least GitHub lets you choose which one to use.

rubund
  • 7,603
  • 3
  • 15
  • 24
1

Adding the following as I had the same problem about specifying a specific public key for some repository:

As per this answer: you can add a configuration per repository as to what ssh command the git client uses. If you want a specific ssh-key used you can do:

git config --local core.sshCommand 'ssh -i <path-to-key>'

Then git will use that command, and thus that key to authenticate with the remote.

MGG
  • 43
  • 7