The goal is to clone a Git repository in Visual Studio Team Services without providing any passwords. The further goal is to do it completely non-interactively, without any prompts at all.
Problem description:
Operating system is Windows Server 2016. Let's say my user name is batman.
I have set up the private key (without passphrase) in Windows at C:\Users\batman\.ssh\id_rsa
.
I have added the public key for my user account at VSTS. All good.
I want to clone the repository and VSTS web UI provides me an SSH URL to the repository. I use it in the following command that I execute:
git clone ssh://[email protected]:22/MyProject/_git/MyRepo
The response:
Cloning into 'MyRepo'...
Enter passphrase for key '/c/Users/batman/.ssh/id_rsa':
[email protected]'s password:
So first it asks for the key passphrase where I just press Enter but the last line is confusing. What password should I input and why is it asking it? How to make it not ask it? How to make the clone command not ask anything at all?
First, it asks for the passphrase to your private key:
Enter passphrase for key '/c/Users/batman/.ssh/id_rsa':
From your comments (in the now deleted answer) I understood that you had used PuTTy to generate the key, and I'm suspecting that your key is not in the correct format (maybe this will help?)(or this?), make sure that it begins with:
-----BEGIN RSA PRIVATE KEY-----
and ends with
-----END RSA PRIVATE KEY-----
Anyway, the public key authentication fails, so it then asks for mycompany
account's password:
[email protected]'s password:
This would not happen if the public key authentication succeeded.
In my interpretation the "... visualstudio.com's password" message is the clear sign that the public key authentication failed (and this should be part of the error message IMHO). In most of the cases it means the private key file was not found or its format is invalid.
For me the solution was easy - simply modified .ssh/config file (I use OpenSSH both on my Windows as well as on Mac). The correct setting I found on Microsoft Docs, bottom of this page
After pasting this into .ssh/config file all started to work perfectly:
# Most common scenario: to use the same key across all hosted Azure DevOps
# organizations, add a Host entry like this:
Host ssh.dev.azure.com
IdentityFile ~/.ssh/your_private_key
IdentitiesOnly yes
# This model will also work if you still use the older SSH URLs with a
# hostname of vs-ssh.visualstudio.com:
Host vs-ssh.visualstudio.com
IdentityFile ~/.ssh/your_private_key
IdentitiesOnly yes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With