sh script doesn't add ssh key to ssh-agent (windows git bash) -


i using github windows on windows 7. have bash script add ssh-key ssh-agent. have setup ssh remote repo.

add_key.sh

#!/bin/bash     cd ../ssh/ eval $(ssh-agent) ssh-add id.rsa cd ../htdocs/ 

execute command-

./add_key.sh 

it returns

agent pid 5548 identity added: id.rsa (id.rsa) 

when git push origin master, fails. when manually cd in ssh directory, , run same ssh-related commands , cd directory htdocs , git push origin master, works.

why happening?

your problem script running in own shell session because running ./add_key.sh.

this means variables set eval $(ssh-agent) not living beyond shell session parent session doesn't have them , cannot use agent (also might spawning new agent each time run script).

the fix run "script" in current session dot-sourcing script instead of running external script.

that want use . add_key.sh.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -