Git SSH public key authentication failed with git on Azure DevOps

Harold Finch
CodeX
Published in
2 min readAug 29, 2024

If you’re encountering issues with SSH public key authentication when trying to use Git with Azure DevOps, here are the steps to troubleshoot and resolve the problem:

1. Ensure SSH Key is Added to Azure DevOps

  • Generate an SSH Key (if you haven’t already):
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

This generates a new SSH key, usually saved in ~/.ssh/id_rsa.

Add the SSH Key to Azure DevOps

  • Copy the contents of your public key file
cat ~/.ssh/id_rsa.pub
  • Go to your Azure DevOps account.
  • Navigate to User Settings (click on your profile picture in the top-right corner).
  • Select SSH Public Keys under the Security section.
  • Click Add and paste your SSH key, then save.

2. Verify SSH Configuration

  • Ensure your SSH config is set correctly. You may want to create or update the ~/.ssh/config file.
Host dev.azure.com
HostName dev.azure.com
User git
IdentityFile ~/.ssh/id_rsa

3. Check SSH Agent

  • Ensure that your SSH key is being used by the SSH agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

4. Test the Connection

  • Test your SSH connection to Azure DevOps
ssh -T git@ssh.dev.azure.com

If everything is set up correctly, you should receive a success message, like

Welcome to Azure Repos!

5. Use the Correct SSH URL

  • Make sure you’re using the correct SSH URL for your Git repository on Azure DevOps. It typically looks like this.
git@ssh.dev.azure.com:v3/organization/project/repository

6. Check for Permissions

  • Ensure that you have the correct permissions to access the repository in Azure DevOps.

7. Debugging

  • If authentication still fails, try enabling SSH verbose mode to get more detailed output
ssh -vvv git@ssh.dev.azure.com
  • This can help you identify where the connection is failing.

Following these steps should help you troubleshoot and resolve issues with SSH public key authentication when using Git with Azure DevOps.

--

--

Harold Finch
CodeX
Writer for

A DevOps Engineer Looking for new challenges