I'm currently looking at setting up a Vagrant environment on my Mac machine, so that I can run vagrant up and it will then install rbenv and ruby and all I need. Then I have a Bash script that will fetch all my repos from github.

The only thing is that my new vagrant vm has to now generate a ssh key and then link it to my Github account. This can be cumbersome. Especially since I would like to share my Vagrant file with all those that have access to our repos so that they could do the same.

So I thought I could try forwarding my hosts ssh to the VM so that the VM can forward my host ssh to Github. Following this article: Githubs walkthrough, I set my hosts ssh config:

Host localhost
    ForwardAgent yes

and set in my vagrant file

Vagrant.configure("2") do |config|
  config.ssh.forward_agent = true

and when I log into my VM and run the following command I get this error:

$ ssh -T git@github.com`
Permission denied (publickey)

Is there anyone that has tried a similar setup? The VM is a precise64 box.



vagrant@precise64:~$ env
SSH_CLIENT= 53068 22
LESSOPEN=| /usr/bin/lesspipe %s
LESSCLOSE=/usr/bin/lesspipe %s %s
  • 1
    What is the output of env once you have entered the virtual machine?
    – Chris Down
    May 27 '13 at 9:19
  • SSH_AUTH_SOCK=/tmp/ssh-aDGJQD2812/agent.2812. It appears to be working. Are you sure you don't have a conflicting SSH agent on the other machine, and the key is correct?
    – Chris Down
    May 27 '13 at 9:34
  • yeah running ssh -T git@github.com works and ssh-add -L shows the key and i only have one of them. brain bashing stuff
    – TheLegend
    May 27 '13 at 9:41
  • 1
    @TheLegend It's a shot in the dark, but have you checked that the ssh-agent is definitely running?
    – djf
    May 27 '13 at 12:44

After a few grueling hours I made headway

Vagrant.configure("2") do |config|
  config.ssh.private_key_path = "~/.ssh/id_rsa"
  config.ssh.forward_agent = true

config.ssh.private_key_path is your local private key Your private key must be available to the local ssh-agent. You can check with ssh-add -L, if it's not listed add it with ssh-add ~/.ssh/id_rsa. Don't forget to add your public key to ~/.ssh/authorized_keys on the Vagrant VM.

Then vagrant reload and rebuild it using the new vagrant config. then it should work test both the host and vagrant using

$ ssh -T git@github.com

vagrant should return the first time

The authenticity of host 'github.com (' can't be established.
RSA key fingerprint is 16:27:ac:a5:7c:28:2d:36:63:2b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,' (RSA) to the list of known hosts.

If you didn't add you public key to ~/.ssh/authorized_keys on the Vagrant VM.

There after it should read as

vagrant@precise64:~$ ssh -T git@github.com
Hi Ruberto! You've successfully authenticated, but GitHub does not provide shell access.

Thank you all that helped me. it was because of you that i went digging further :)

  • 3
    Mine doesn't say "Hi Ruberto!". Is it okay if it says a different name there? Oct 7 '15 at 14:24
  • 1
    Yeah @user973810 its just a response from Github, so it should be the name you have registered with Github with.
    – TheLegend
    Oct 9 '15 at 5:10
  • 1
    Please warn about the implications of vagrant destroy. I just lost a week of work because of this, I thought it would only destroy the configuration.
    – A1rPun
    Jan 29 '19 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.