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.

  1. 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 than my_devops_sshkey that’s appropriate for your use.

  2. 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.

  3. 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:
    Azure DevOps: Create SSH Key to Authorize Git on macOS 1
  4. 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.
    Azure DevOps: Create SSH Key to Authorize Git on macOS 2
    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.

Microsoft MVP

Chris Pietschmann is a Microsoft MVP (Azure & IoT) and HashiCorp Ambassador (2021) with 20+ years of experience designing and building Cloud & Enterprise systems. He has worked with companies of all sizes from startups to Fortune 100. He is also a Microsoft Certified Azure Solutions Architect and developer, a Microsoft Certified Trainer (MCT), and Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.