Bruce
Bruce

Reputation: 1688

Git: which key do I use (may not be by default)?

In my local environment (Mac OS X) I have at my home folder the .ssh folder, where there are two keys: github_rsa and id_rsa; in addition, there is a known_hosts file saying some like:

github.com,192.30.252.131 ssh-rsa blahblah
192.30.252.129 ssh-rsa blahlllblahhhh
...

Is there a way (command line preferred) for me to know which key my git command is using when interacting with Github or Bitbucket? If so, how?

Thanks.

Upvotes: 2

Views: 220

Answers (2)

Mudassir Razvi
Mudassir Razvi

Reputation: 1833

The known-host file that you have given in the question has the public ssh-keys of the respective servers.

The private-public key pair are supposed to be for authentication!

Your .ssh folder is supposed to have two keys 1. Private key and 2. Public key. Public key has extension .pub and private key dosen't have any!

So most probably the two files that you have are one is Public (Which will also be there on github) and private.

Anyhow To know which key your github is using you can do this:

  1. Find the public key in your github account and find its pair in your .ssh folder (i.e if you have maintained a proper nomenclature).
  2. OR else Take your private key and run the command ssh-keygen -y -f <private key file>, it will create a public key. Compare the generated pub-key with your github!

Hope this explains a lot more than the question for your future use! :)

Upvotes: 1

Daniel Bank
Daniel Bank

Reputation: 3899

The id_rsa.pub file contains the RSA public key for your user (generally the key used for connecting to GitHub, if you follow their tutorial). If you want to use the github_rsa key, you can change the key used to connect to GitHub by creating a new host definition in the ~/.ssh/config file:

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

By the way, the known-hosts file contains the servers you have connected to and their public keys.

See also this SO question: Setting up ssh keys for GibHub

Upvotes: 2

Related Questions