Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesridgway/e6c921acc34e6f61922cf31834cb2b02 to your computer and use it in GitHub Desktop.
Save jamesridgway/e6c921acc34e6f61922cf31834cb2b02 to your computer and use it in GitHub Desktop.
Cloning with a different SSH key

Use-case

You need to use an SSH key to authenticate against a service which isn't your default SSH key, and/or your default key may be used on another (different) accout for the service.

Solution

  1. Clone the repo

    GIT_SSH_COMMAND='ssh -i ~/.ssh/your-private-key-filename -o IdentitiesOnly=yes' git clone git@....
    
  2. Edit the .git/config file within the newly cloned repo. Under core add the git SSH command used above as sshCommand:

    e.g.

    [core]
            repositoryformatversion = 0
            filemode = true
            bare = false
            logallrefupdates = true
            ...
            sshCommand = ssh -i ~/.ssh/your-private-key-filename -o IdentitiesOnly=yes
    ...
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment