Caveira
Caveira

Reputation: 61

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.

Upvotes: 0

Views: 57

Answers (2)

zori
zori

Reputation: 2278

Instead of trying to use ssh or scp, you can just use synced_folder, if all VMs are created from the same directory, there should be already mount /vagrant directory that is the same for all VM, if you can just add another synced_folder, for example

config.vm.synced_folder "/full/path/on/host/", "/path/in/vm"

Another way if you want ssh you can create additional ssh key (using ssh-keygen -t ed25519 -f ./my_key), and copy them into VMs during creation look here for details, of course you need also copy private key, so then during connection for ssh you can pass argument -i my_key, as all hosts will have the same public and private key it should work. (Keep in mind it's not secure as normally private key shouldn't be shared)

Upvotes: 1

Matthias Reissner
Matthias Reissner

Reputation: 365

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 [email protected]

Upvotes: 1

Related Questions