Easiest way to copy a single file from host to Vagrant guest?

LeeXGreen picture LeeXGreen · May 23, 2013 · Viewed 173.4k times · Source

I have a use case where I occasionally want to copy a single file from my host machine to the Vagrant guest.

I don't want to do so via traditional provisioners (Puppet / Chef) because this is often a one-off -- I just want something quick to add to my Vagrantfile.

I don't want to share an entire directory, possibly because I want to overwrite an existing file without nuking an entire directory on the guest.

It also seems a bit overkill to write a shell provisioning script, and deal with potential escaping, when all I want to do is copy a file.

So, what's the easiest way to copy a single file from host to guest?

Answer

Luca Invernizzi picture Luca Invernizzi · Feb 6, 2015

Since you ask for the easiest way, I suggest using vagrant-scp. It adds a scp command to vagrant, so you can copy files to your VM like you would normally do with scp.

Install via:

vagrant plugin install vagrant-scp

Use it like so:

vagrant scp <some_local_file_or_dir> [vm_name]:<somewhere_on_the_vm>