ssh-agent forwarding for a Vagrant VM
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
end
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 [email protected]
vagrant should return the first time
The authenticity of host 'github.com (204.232.175.90)' 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,205.232.175.93' (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 [email protected]
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 :)
Related videos on Youtube
TheLegend
Updated on September 18, 2022Comments
-
TheLegend over 1 year
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 installrbenv
andruby
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 ... end
and when I log into my VM and run the following command I get this error:
$ ssh -T [email protected]` Permission denied (publickey)
Is there anyone that has tried a similar setup? The VM is a precise64 box.
EDIT:
env
:vagrant@precise64:~$ env TERM=xterm-256color SHELL=/bin/bash SSH_CLIENT=10.0.2.2 53068 22 SSH_TTY=/dev/pts/0 LC_ALL=en_US USER=vagrant LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36: RBENV_ROOT=/opt/rbenv SSH_AUTH_SOCK=/tmp/ssh-aDGJQD2812/agent.2812 MAIL=/var/mail/vagrant PATH=/opt/rbenv/shims:/opt/rbenv/bin:/opt/rbenv/bin/rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/vagrant_ruby/bin PWD=/home/vagrant SHLVL=1 HOME=/home/vagrant LOGNAME=vagrant SSH_CONNECTION=10.0.2.2 53068 10.0.2.15 22 LC_CTYPE=UTF-8 LESSOPEN=| /usr/bin/lesspipe %s LESSCLOSE=/usr/bin/lesspipe %s %s _=/usr/bin/env
-
clerksx almost 11 yearsWhat is the output of
env
once you have entered the virtual machine? -
clerksx almost 11 years
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? -
TheLegend almost 11 yearsyeah running
ssh -T [email protected]
works andssh-add -L
shows the key and i only have one of them. brain bashing stuff -
djf almost 11 years@TheLegend It's a shot in the dark, but have you checked that the ssh-agent is definitely running?
-
-
Johannes Jarolim over 8 yearsMine doesn't say "Hi Ruberto!". Is it okay if it says a different name there?
-
TheLegend over 8 yearsYeah @user973810 its just a response from Github, so it should be the name you have registered with Github with.
-
A1rPun over 5 yearsPlease 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.