vagrantfile-transfer

Vagrant transfer file from Guest VM to another Guest VM


Is there any option to transfer a simple file from one Vagrant VM to another Vagrant VM?

I assigned static IP to both of the VMs, watched for open SSH ports and tried to use scp command to transfer the file, but, unfortunately it returns error "permission denied(publickey)" which is reasonable.

Im looking for another way to transfer the file to the target guest VM (for example to transfer the public key to the target VM and then SSH to it) alternatives to scp.

I have tried scp, but permission denied for not authorized public key.

Also, I tried to transfer pub key to the host, then copy manually to each VM, but its not efficient for as much as 1..N VMs large enough.


Solution

  • Here is an example for a multi machine environment. Each vagrant vm have its own key in the directory

    /vagrant/.vagrant/machines/myname/provider_name/private_key

    Add this line to your Vagrantfile:

    config.vm.synced_folder ".", "/vagrant", type: "virtualbox", mount_options: ["dmode=700","fmode=700"]
    

    use ssh or scp:

    ssh -i /vagrant/.vagrant/machines/app/virtualbox/private_key vagrant@10.0.0.11