Instead of using username / password to authenticate with the Git (git
) command-line when cloning repositories, Git supports the use of the more secure option to use SSH Public / Private Key Pairs. Here’s the simple steps to follow to generate an SSH Key Pair and set it up with Azure DevOps Repositories to be able to use Git locally to clone and work with those repositories using the Git CLI.
- You first need to generate a new SSH key pair. This command will create a new public / private SSH key that will be used to authenticate Git with Azure DevOps:
ssh-keygen -t rsa -m PEM -f "/Users/<username>/.ssh/my_devops_sshkey" -C "my_devops_sshkey"
Replace the<username>
placeholder with your local username for your/Users/
folder.
Also, you’ll want to name the SSK Key something other thanmy_devops_sshkey
that’s appropriate for your use. - Next, the Private Key needs to be added to the macOS Key Chain so it can be used. This command will add it for you:
ssh-add --apple-use-keychain /Users/<username>/.ssh/my_devops_sshkey
Replace the<username>
placeholder with your local username for your/Users/
folder. - Now that you have a Public/Private SSH Key pair generated with the Private key registered with macOS for use, you need to add it to Azure DevOps SSH Keys to support your use of this key pair for authenticating
git
to be able to clone repositories. Navigate into your Azure DevOps, then go to User Settings -> SSH public keys and add the/Users/<username>/.ssh/my_devops_sshkey.pub
Public Key file contents there key there: - Now that you have the new SSH key pair created, registered locally, and registered in Azure DevOps SSH Keys, you’ll now be able to Git Clone (
git clone
) repositories in your Azure DevOps organization using the SSH repository location.
Here’s an example Git CLI clone command using the SSH URL location for an Azure DevOps git repository:git clone git@ssh.dev.azure.com:v3/<org>/<project>/<repo>
The above steps includes some placeholders like <username>
, <project>
and others that you’ll need to fill in with your appropriate values before running these commands.
Worked! Thank you Chris
Thank you very much!