Switching between multiple ssh keys in Git on Windows

I need to have multiple keys in my client to access two different accounts on Repository hosting. See https://redefy.repositoryhosting.com/support -> How do I manage multiple accounts with multiple keypairs on my client?

I do not understand how to change between different ssh keys in Git on Windows, can anybody help me?

  • git: Pulling only certain files
  • Add all files to a commit except a single file?
  • Ignoring an already checked-in directory's contents?
  • How to delete a file tracked by git-lfs and release the storage quota?
  • Create Git commits and push to GitHub with Ruby
  • How do you stash only files that have been added?
  • Git Repositories and History Hijinks
  • git look commit log for commit id
  • Are there any differences between creating a branch based on branch foo or bar if they point to the same commit in Git?
  • What is the correct way to convert SVN remote branches and tags into local Git branches/tags during SVN to Git migration
  • should minified files be committed into source control?
  • How to clone and integrate external (from git) cmake project into local one
  • 4 Solutions collect form web for “Switching between multiple ssh keys in Git on Windows”

    I assume you use git bash and openssh.

    Like what it’s written in the article, you can make a configuration file for ssh client that lists all of your accounts. You can write the following configuration in your own ssh client configuration file in ~/.ssh/config

    Host account-one
    HostName server.example.com
    User user-one
    IdentityFile ~/.ssh/key-one
    Host account-two
    HostName server.example.com
    User user-two
    IdentityFile ~/.ssh/key-two

    What it says is you define two, kind of, “host aliases” named account-one and account-two. If you use them, when making connection, the ssh client will use the corresponding HostName, User, and IdentityFile for the server address, username, and ssh key file. With this you can use them to access your accounts and keys at even the same server.

    In git, you can define two remotes using them

    $ git remote add one account-one:repository.git
    $ git remote add two account-two:repository.git

    then you can push to those remotes

    $ git push one master
    $ git push two master

    Which key is used for which server is handled by the SSH program that git is using to connect. In the default setup this should be the command line SSH client (openSSH?).

    Using openSSH you can configure particular keyfiles for particular hosts in the ~/.ssh/config file:

    Host foo.example.com
      IdentityFile ~/.ssh/foo.example.com-id_rsa
    Host bar.example.com
      IdentityFile ~/.ssh/bar.example.com-id_rsa

    Where ~/.ssh/*.example.com-id_rsa are the private key files for each server.

    I hope this helps.

    On Windows you should try Pageant an SSH authentication agent for PuTTY, PSCP, PSFTP, and Plink. This tool can manage yout ssh keys and its pass-phrases.
    To use it together with Git you have to install Putty and link to the plink.exe setting the GIT_SSH variable.

    1. Install Putty and friends (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)
    2. Set GIT_SSH

      set GIT_SSH=<path-to-plink.exe>

    3. Start Pageant and add you keys
    4. Run Git


    I’ll answer this a little indirectly. I have previously used git bash and I’ve found that when I’m using git via the git bash shell, that it behaves just like a mac or linux bash shell. Meaning, when using git bash, that I can answer your question like:

    ‘If you use git bash, you can manage multiple accounts just as you would if you were on linux or mac, using ssh-agent/ssh-add and friends’

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