Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ssh agent forwarding with "vagrant ssh"?

Rather than create a new SSH key pair on a vagrant box, I would like to re-use the key pair I have on my host machine, using agent forwarding. I've tried setting config.ssh.forward_agent to TRUE in the Vagrantfile, then rebooted the VM, and tried using:

vagrant ssh -- -A 

...but I'm still getting prompted for a password when I try to do a git checkout. Any idea what I'm missing?

like image 581
Matt V. Avatar asked Aug 14 '12 15:08

Matt V.


People also ask

How do I connect my vagrant box to SSH?

Simply CMD-SHIFT-P then "Remote-SSH: Connect to Host..." and the ssh . config entry you just added is automatically listed - you simply select it and voila, vscode connects to your remote vagrant vm!

What is SSH agent forwarding?

SSH agent forwarding can be used to make deploying to a server simple. It allows you to use your local SSH keys instead of leaving keys (without passphrases!) sitting on your server. If you've already set up an SSH key to interact with GitHub, you're probably familiar with ssh-agent .

Is Openssh authentication agent safe?

It runs in the background on your system, separately from ssh , and it usually starts up the first time you run ssh after a reboot. The SSH agent keeps private keys safe because of what it doesn't do: It doesn't write any key material to disk. It doesn't allow your private keys to be exported.


2 Answers

I'm using vagrant 2 on OS X Mountain Lion.

Vagrant.configure("2") do |config|   config.ssh.private_key_path = "~/.ssh/id_rsa"   config.ssh.forward_agent = true end 
  1. config.ssh.private_key_path is your local private key
  2. 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
  3. Don't forget to add you public key to ~/.ssh/authorized_keys on the Vagrant VM. You can do it copy-and-pasting or using a tool like ssh-copy-id
like image 88
LuizSignorelli Avatar answered Sep 21 '22 14:09

LuizSignorelli


Add it to the Vagrantfile

Vagrant::Config.run do |config|    # stuff    config.ssh.forward_agent = true end 

See the docs

like image 30
EnabrenTane Avatar answered Sep 24 '22 14:09

EnabrenTane