Search code examples
batch-filesshgit-clone

How to provide password when run git clone command with a batch file


I am making a batch file that automatically clones a git repository. I put the following line to the batch file

git clone ssh://user@address/path

But its execution hits me:

[exec] Permission denied, please try again.
[exec] Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
[exec] fatal: Could not read from remote repository.

Because it requires to enter the password. I tried changing the command to

git clone ssh://user:password@address/path

But it stills asking me for the password

Any suggestion?


Solution

  • You can use sshpass tool to provide passwords to the git:

    sshpass -p password git clone ssh://user@address/path
    

    But note that it is not security-wise and using keys is much better alternative.