I have to clone several repositories on the VM-s and then building software on them. I have pretty nice build script but there is one issue. Before build, several repos should be cloned, and after some security updates, I am not allowed to add my public key to git server and also only supported protocol is ssh.

The cloning command looks like follow:

git clone ssh://userA@git-ger-XXX.com:YYYY/repoB

but there are plenty of them and passing password after each of them is really annoying and time-consuming.

What I am trying to do is to pass automatically password to clone command. I was trying add userA:passwordA@git-ger.... but it works only for HTTPS, not ssh. I know that I have to switch to some automatic tools like ansible to make automatic deployment but it took me a lot of time to rewrite whole building process.

My question is how I can automatically pass a password to clone repo, without changing anything on the server. Ideally, would be to do this from bash level. I was trying reading lines after typing git clone but it also didn't work for me. Any help will be appreciated

  • you can try sshpass. It should work also for your use case. – Jakuje Apr 19 '16 at 18:14

IMO the best solution is using a custom GIT_ASKPASS helper and deliver the password as another environment variable. So for example, create a file git-askpass-helper.sh as:

exec echo "$GIT_PASSWORD"

and then run git clone https://username@hostname/repo with environment variables GIT_ASKPASS=/path/to/git-askpass-helper.sh and GIT_PASSWORD=nuclearlaunchcodes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.