Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
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
@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
add comment

1 Answer

up vote 1 down vote accepted

after a few grooling hours 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 you public key to ~/.ssh/authorized_keys on the Vagrant VM.

then vagrant destroy 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 didnt 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 :)

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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