Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clone with username password authentication in one go

Tags:

git

bash

ssh

My current command is

git clone ssh://[email protected]/srv/git/repo

after that

password

... fine, works good.

Now I would like do this in one line. Something like that:

git clone ssh://username:[email protected]/srv/git/repo

but it`s not working and gives me the message:

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

How can I clone in a single line?

like image 665
andrew Avatar asked Apr 19 '15 10:04

andrew


People also ask

How do I clone a private Git repository with username and password?

If you want to clone it to a specific folder, just insert the folder address at the end like so: git clone https://<token>@github.com/<username>/<repository.git> <folder> , where <folder> is, you guessed it, the folder to clone it to! You can of course use . , .. , ~ , etc.

How do I clone a Git repository with username?

In order to clone a git repository into a specific folder, execute the “git clone” command and specify the destination folder at the end. $ git clone https://github.com/username/project.git myproject Cloning into 'myproject'... remote: Enumerating objects: 813, done.

Does git clone require password?

As we had mentioned earlier on, when cloning a remote Git repository over HTTP(S), every connection needs a username and password as shown.


1 Answers

You should be able to use the http url instead to clone it:

git clone http://username:[email protected]/srv/git/repo.git

Edit:

If in case you can do this by normal ssh only with username-password credentials, try using sshpass like:

sshpass -p password git clone ssh://[email protected]/srv/git/repo

You might have to install sshpass for this.

Note that this is the case when the ssh keys are not correctly configured; if the ssh keys were configured, your public key would be shared with the target server and you wouldn't have needed to enter the password (you might have had to enter a passphrase though).

like image 149
Anshul Goyal Avatar answered Oct 06 '22 03:10

Anshul Goyal