use ssh private key from host in vagrant guest

前端 未结 3 2075
庸人自扰
庸人自扰 2021-02-02 12:24

I want to clone a bunch of private git repositories while provisioning a vagrant box. According to this article this should be possible using config.ssh.forward_agent = tr

相关标签:
3条回答
  • 2021-02-02 12:59

    Please check whether your host system has ssh-agent forwarding enabled. You can do so for example by adding this block to your ~/.ssh/config file:

    Host                    *
      ForwardAgent          yes 
    

    If this is enabled vagrant ssh (and also vagrant provision) should be able to forward your key to the guest machine.

    You also might want to check using ssh-add -l whether your ssh-agent does know about your SSH-key. If it is in the list and you have agent-forwarding activated you should have a success. Otherwise you can add the key to your ssh-agent by running ssh-add <path to your key file>.

    0 讨论(0)
  • 2021-02-02 13:17

    Tom,

    What you're doing is fairly generic in nature and I don't think is Vagrant specific.

    Try some of the following to track down the issue:

    1. edit your /etc/ssh/sshd_config
    2. Set LogLevel debug
    3. Restart the sshd service sudo service sshd restart or /etc/init.d/sshd restart
    4. tail -f /var/log/authlog -- note, the file may be something else like /var/log/authd.log or /var/log/secure or something.
    5. Watch what happens when you connect. It should give you some indication of why it's failing.

    Again sorry, I'm not that familiar with Vagrant but I'm wondering if the provisioning script is running as another user, in which case the agent forwarding may not work as expected?

    0 讨论(0)
  • 2021-02-02 13:25

    It sounds like you may be hitting this particular bug: https://github.com/mitchellh/vagrant/issues/1735 (Despite it being "closed" it's actually not fixed)

    On Windows, SSH Forwarding in Vagrant does not work properly by default (because of a bug in net-ssh).

    However, there is a workaround or simple hack. You can auto-copy your local SSH key to the Vagrant VM via a simple provisioning script in your VagrantFile. Here's an example: https://github.com/mitchellh/vagrant/issues/1735#issuecomment-25640783

    0 讨论(0)
提交回复
热议问题