Blog › Git · Published 2026-11-26

How to tell Git which private SSH key to use

If you have several SSH keys, you can tell Git which one to use.

For one repository

git config core.sshCommand "ssh -i ~/.ssh/id_work -o IdentitiesOnly=yes"

This is stored in that repository only.

For one command

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_work -o IdentitiesOnly=yes" git clone git@github.com:owner/repo.git

With an SSH config file

Add an entry in ~/.ssh/config:

Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_work
  IdentitiesOnly yes

Then use git@github-work:owner/repo.git as the remote address.

IdentitiesOnly yes stops SSH from trying other keys offered by an agent.

Official sources

Need help with your project?
We build websites, systems and automation. Start your project WhatsApp

All articles