Skip to content

Instantly share code, notes, and snippets.

@praveen-palanisamy
Created June 23, 2022 20:19
Show Gist options
  • Save praveen-palanisamy/d2cdad8a405626cba93c34b381376b70 to your computer and use it in GitHub Desktop.
Save praveen-palanisamy/d2cdad8a405626cba93c34b381376b70 to your computer and use it in GitHub Desktop.
Git ssh command for clone, pull from Azure Dev Ops remote using SSH-RSA keys

Sometimes git clone/pull using SSH keys would fail with the following message even when the SSH keypair is setup on the server:

Unable to negotiate with <GIT_SERVER_IP> port 22: no matching host key type found. Their offer: ssh-rsa
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

The resolution is to ask git to use the the following SSH options:

GIT_SSH_COMMAND="ssh -vvv -oHostKeyAlgorithms=+ssh-rsa -oIdentityFile=~/.ssh/id_rsa -oPubkeyAcceptedKeyTypes=+ssh-rsa"

Explanation of arguments:

  1. (optional) -vvv: Very very verbose. Prints out lots of details as the SSH connection is made

  2. -oHostKeyAlgorithms=+ssh-rsa: Use ssh-rsa during handshakes with the server

  3. -oIdentityFile=: Path to the private SSH key for authentication

  4. -oPubkeyAcceptedKeyTypes=ssh-rsa: Allow ssh-rsa

Examples: Azure Dev Ops (ADO) repo using SSH-RSA key pair

  1. Clone : GIT_SSH_COMMAND="ssh -vvv -oHostKeyAlgorithms=+ssh-rsa -oIdentityFile=~/.ssh/id_rsa -oPubkeyAcceptedKeyTypes=+ssh-rsa" git clone [email protected]:v3/Org/Project/Repo
  2. Pull: GIT_SSH_COMMAND="ssh -vvv -oHostKeyAlgorithms=+ssh-rsa -oIdentityFile=~/.ssh/id_rsa -oPubkeyAcceptedKeyTypes=+ssh-rsa" git pull

Alternatives

You can also update your SSH config file to set the aboce options by default for this Git remote. On Linux, add the following to ~/.ssh/config file:

Host gitserver1
    HostName vs-ssh.visualstudio.com
    User bizair
    IdentityFile ~/.ssh/id_rsa
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment