Created
July 20, 2020 19:14
-
-
Save lordlycastle/63584c7492d4756f199161a4b3b9b42e to your computer and use it in GitHub Desktop.
example of how to use host alias to separate keys for same host but different sub route. taken from: https://docs.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops&tabs=current-page#q-i-have-multiple-ssh-keys--how-do-i-use-different-ssh-keys-for-different-ssh-servers-or-repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The settings in each Host section are applied to any Git SSH remote URL with a matching hostname. | |
# Generally: | |
# * SSH uses the first matching line for each parameter name, e.g. if there's multiple values for a | |
# parameter across multiple matching Host sections | |
# * "IdentitiesOnly yes" prevents keys cached in ssh-agent from being tried before the IdentityFile | |
# values we explicitly set. | |
# * On Windows, ~/.ssh/your_private_key maps to %USERPROFILE%\.ssh\your_private_key, e.g. | |
# C:\Users\<username>\.ssh\your_private_key. | |
# To use the same key across all hosted Azure DevOps organizations, where the SSH URL host is | |
# ssh.dev.azure.com (like [email protected]:v3/some_organization/some_project/some_repo), add | |
# the Host section below: | |
Host ssh.dev.azure.com | |
IdentityFile ~/.ssh/your_private_key | |
IdentitiesOnly yes | |
# Since all hosted Azure DevOps URLs have the same hostname (ssh.dev.azure.com), if you need | |
# different keys for different organizations (or just different repos within the same organization), | |
# you'll need to use host aliases to create separate Host sections. | |
# | |
# Imagine that we have the following two SSH URLs: | |
# * [email protected]:v3/org1/org1_project/org1_repo | |
# * For this, we want to use key1, so we'll use devops_key1 as the Host alias. | |
# * [email protected]:v3/org2/org2_project/org2_repo | |
# * For this, we want to use key2, so we'll use devops_key2 as the Host alias. | |
# | |
# You'll need to substitute ssh.dev.azure.com with the Host alias in the SSH URL you use with Git. | |
# The SSH URLs above become: | |
# * git@devops_key1:v3/org1/org1_project/org1_repo | |
# * git@devops_key2:v3/org2/org2_project/org2_repo | |
# | |
# To set explicit keys for the two host aliases and to tell SSH to use the correct actual hostname, | |
# add the next two Host sections: | |
Host devops_key1 | |
HostName ssh.dev.azure.com | |
IdentityFile ~/.ssh/private_key_for_org1 | |
IdentitiesOnly yes | |
Host devops_key2 | |
HostName ssh.dev.azure.com | |
IdentityFile ~/.ssh/private_key_for_org2 | |
IdentitiesOnly yes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment