BaltoStar
BaltoStar

Reputation: 8967

windows git bash on startup can't find agent.env

Windows 10
Git for Windows 64 v2.13.0.windows.1

To config ssh with private-key passphrase I'm following this GitHub doc :

https://help.github.com/articles/working-with-ssh-key-passphrases/

Specifically, I add to my ~/.ssh/.bashrc the following script:

env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi

unset env

However when I start Git Bash it can't find ~/.ssh/agent.env :

bash: env=~/.ssh/agent.env: No such file or directory
bash: : No such file or directory
bash: : No such file or directory
Could not open a connection to your authentication agent.

What is agent.env and how is it typically installed or what should it contain ?

Upvotes: 3

Views: 3064

Answers (5)

Darl Aigbokie
Darl Aigbokie

Reputation: 1

The file '~/.ssh/agent.env' doesn't exist and the script isn't checking if it does or not and creating it if it doesn't. Which means you would have to create the yourself before it gets assigned to env.

Upvotes: 0

csrowell
csrowell

Reputation: 924

For others who end up here trying to figure out why their script isn't executing when they add it to either ~/.profile or ~/.bashrc, I found I needed to add it to ~/.bash_profile for it to get picked up and used by Git Bash on Windows.

Upvotes: 0

Thomas Müller
Thomas Müller

Reputation: 21

I know it's an old thread, but maybe i can help some others who run across this problem. In my case, I simply had to create the .ssh folder in the user profile to get this working.

Upvotes: 2

Jeff Shepler
Jeff Shepler

Reputation: 2105

I know this is old, but this just happened to me and this is what I found.

For me, it ended up being the encoding of the file including the byte order mark (BOM), which got interpreted as part of the first line and so instead of setting the "env" variable, it thought it was executing a command (the first error in your output supports this).

You can confirm by adding echo "env = $env" as the 2nd line and you'll see "env = ", showing that the env variable isn't set.

I had created .bashrc using notepad++ and it defaults to utf-8 with BOM. You can change the encoding (the encoding menu) to utf-8 or ANSI, re-save the file, and it should now work as expected.

Alternatively, delete the file and re-create it from bash:

cd ~/
rm .bashrc
umask 077
touch .bashrc

then edit the file and paste your script.

Upvotes: 0

jasonlcy91
jasonlcy91

Reputation: 464

Point ssh-add to the file, eg ssh-add ~/.ssh/id_rsa or c:/somenondefaultlocation/.ssh/id_rsa

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add

Also, make sure you set the same directory for the first line, eg env=~/.ssh/agent.env or env=c:/somenondefaultlocation/.ssh/agent.env

Upvotes: -1

Related Questions