Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Provide passphrase to git in bash script

How do I provide passphrase with git fetch/pull in bash script. I really need to do it in a bash script, without using ssh-add or something like that. is it possible?

like image 735
GALIAF95 Avatar asked Dec 08 '15 11:12

GALIAF95


People also ask

How do you enter a passphrase for a Key?

$ ssh-keygen -p -f ~/. ssh/id_ed25519 > Enter old passphrase: [Type old passphrase] > Key has comment '[email protected]' > Enter new passphrase (empty for no passphrase): [Type new passphrase] > Enter same passphrase again: [Repeat the new passphrase] > Your identification has been saved with the new passphrase.

How can I have Git remember the passphrase for my Key on Windows?

Enable the ssh-agent service, use ssh-add to add your key to the ssh store, and set GIT_SSH in your environment (if necessary) and git/ssh will remember your passphrase via ssh-agent.


1 Answers

I tryed ssh-agent and solution with SSH_ASKPASS but nothing worked, then I found a solution using http://expect.sourceforge.net/

Example(executed in shell):

pass="passwod"
/usr/bin/expect <<EOD
spawn git fetch origin $BRANCH
expect "Enter passphrase for key '/home/$USERNAME/.ssh/id_rsa': "
send "$pass\r"
expect eof
EOD
like image 88
GALIAF95 Avatar answered Oct 11 '22 08:10

GALIAF95