Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SaeedPrez's avatar

Homestead: Could not open a connection to your authentication agent.

Hello guys,

I've recently ran into this problem where more or less every now and then I can't use git push, I get this error message:

Permission denied (publickey).
fatal: Could not read from remote repository.

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

When I try to add my public key, I get this error:

$ ssh-add ~/.ssh/id_rsa
Could not open a connection to your authentication agent.

After some google:ing, I found I have to start the ssh-agent first:

$ eval $(ssh-agent)
$ ssh-add ~/.ssh/id_rsa

I tried adding those lines to after.sh found in the C:\Users\<user>\.homestead folder and I can see it running when I boot vagrant:

    homestead-7: Running: script: Update Composer
==> homestead-7: You are already using composer version 1.3.2 (stable channel).
==> homestead-7: Running provisioner: shell...
    homestead-7: Running: E:/Dropbox/Programs/ConEmu/Data/Temp/vagrant-shell20170128-4104-1vsi5bt.sh
==> homestead-7: Agent pid 3711
==> homestead-7: Identity added: /home/vagrant/.ssh/id_rsa (/home/vagrant/.ssh/id_rsa)

Z:\Work\Homestead>

..but it still doesn't work when I SSH in. I have to run it manually..

Any thoughts how I can stop ssh-agent from dying?

PS. I'm on Windows 10

0 likes
3 replies
SaeedPrez's avatar

I added below lines to ~/.bashrc which seems to work even after vagrant halt/up. But I'm still not sure why I have to do this manually and if I have to do this every time I create a new box (which I don't do very often)..

eval $(ssh-agent)
ssh-add ~/.ssh/id_rsa
mikkolauhakari's avatar
Level 9

I would do all git stuff on your local machine, not through (inside) the Vagrant machine. Your ssh keys should reside on your own machine not a virtual one!

:)

Please or to participate in this conversation.