sh script doesn't add ssh key to ssh-agent (windows git bash)
#!/bin/bash cd ../ssh/ eval $(ssh-agent) ssh-add id.rsa cd ../htdocs/
Agent pid 5548 Identity added: id.rsa (id.rsa)
Why is this happening?
One Solution collect form web for “sh script doesn't add ssh key to ssh-agent (windows git bash)”
Your problem is that your script is running in its own shell session because you are running
This means that the variables set by
eval $(ssh-agent) are not living beyond that shell session so the parent session doesn’t have them and cannot use the agent (also you might be spawning a new agent each time you run the script).
The fix for this is to run that “script” in the current session by dot-sourcing the script instead of running it as an external script.
That is you want to use