GIT and SSH, which key is used?

Say your .ssh directory contains 30 keys (15 private and 15 public)

Where in GIT, can one check which one is used to connect to a given remote repo?

  • One source needs to compile differently on multiple machines
  • Git - undoing git rm
  • How do I rewrite committer names in a git repository?
  • Git reset failing after find and replace
  • How can I amend a previous git commit
  • How to follow a file in git
  • git annex / ssh : ControlPath too long
  • How Can I View All Files Changed on a Branch in Git
  • How to use the “colon slash” revision short form and still refer to a commit's parent?
  • How to let git check for updates on the master server?
  • Git Fast-Forward Merge requires a pull first
  • Promote all builds to master on Jenkins
  • 5 Solutions collect form web for “GIT and SSH, which key is used?”

    The following entry in .ssh/config file solves the problem

      host git.assembla.com
      user git
      identityfile ~/.ssh/whatever
    

    Where ~/.ssh/whatever is a path to your private key

    Additionally, user and host can be picked up from

    git push git@git.assembla.com:repo_name.git
             ^__ ^_______________
             user host
    

    Executing ssh in verbose mode, aka ssh -v user@host, will print a huge load of debugging info, which also contains details on which keyfiles it is trying for login.

    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: /home/user/.ssh/id_rsa
    debug1: Server accepts key: pkalg ssh-rsa blen 332
    debug1: read PEM private key done: type RSA
    debug1: Authentication succeeded (publickey).
    

    Now if you combine this, with the Step 4 in Git’s own SSH help page, ssh -vT git@github.com can give you the answer.

    Note: You can also use the -i switch to tell ssh during command execution, which keyfile to use.

    Since git just uses ssh to connect, it will use whichever key ssh would use to connect to the remote host. See the ~/.ssh/config file for details; the host block uses the IdentityFile directive to specify the private key to use. The ssh_config(5) manpage contains full details.

    Unless it is specified on the .ssh/config it will use the default private key file.

    The default file is ~/.ssh/id_rsa or ~/.ssh/id_dsa or ~/.ssh/identity depending on the protocol version.

    On the remote server, edit the sshd_config file and change LogLevel from INFO to VERBOSE and restart ssh.

    Now your log file will hold the fingerprint of the key that was used to authenticate each user.

    On Ubuntu, these files are:

    /etc/ssh/sshd_config
    /var/log/auth.log
    

    but they may be different on another distro. Just google for their location (some use /var/log/secure for example).

    Git Baby is a git and github fan, let's start git clone.