Mehdi
Mehdi

Reputation: 1306

copy file from host to vagrant virtual machine

I am new with virtual machine. I want to copy a file from host (Mac) to vagrant virtual machine. I could not share a folder, so I want to use command line. How can I copy a file from host to vagrant virtual machine with command line?

Upvotes: 8

Views: 8287

Answers (3)

gavenkoa
gavenkoa

Reputation: 48943

There is an officially supported command vagrant upload:

vagrant upload source [destination] [name|id]

Upvotes: 4

aprasanth
aprasanth

Reputation: 1099

To copy a file from the host to vagrant:

scp -P 2222 /path/to/file [email protected]:.
  • By default The vagrant instance uses port 2222 and ip 127.0.0.1. The password for vagrant is 'vagrant'. The file will be copied to the home of vagrant.

To copy a file from vagrant to host machine:

scp -P 2222 [email protected]:/path/to/file

Upvotes: 9

Frederic Henri
Frederic Henri

Reputation: 53813

one easy way is to let vagrant handles the copy through the File Provisioner :

config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"

If you really want to use a command line, it might be dependant on your VM, assuming you have linux based VM, you could use scp and copy the file through ssh. see https://unix.stackexchange.com/a/106482

Upvotes: 4

Related Questions