Tech TLDR;

  • Archive
  • Top Posts
  • GitHub
  • LinkedIn
  • Contact

How to Copy One File from Vagrant Virtual Machine to Local Host

February 10, 2017 by admin

Step 1.

Find what port Vagrant is connected to by running vagrant port

The output Will look as follow:

The forwarded ports for the machine are listed below. Please note that
these values may differ from values configured in the Vagrantfile if the
provider supports automatic port collision detection and resolution.

    22 (guest) => 2200 (host)
Code language: JavaScript (javascript)

Indicating that Vagrant is running on port 2200

Step 2.

Get the absolute path for the file that you want to copy i.e. /vagrant/some-file.txt

You can get it by ssh’ing into the machine and locating the needed file

Step 3.

Make sure you are in your host machine and use SCP command to copy over the file

scp -P 2200 vagrant@127.0.0.1:/vagrant/some-file.txt .Code language: JavaScript (javascript)

Note that:

  • -P points to port from step 1
  • username is vagrant
  • Your password, is most likely vagrant as well
  • IP is 127.0.0.1 which is just your localhost
  • There is a : after the IP and before the path to the file
  • There is a space and . after the path of the file, indicating that you want to save the file into the current directory.

You can use the same trick to ssh into vagrant the machine (instead of the built in vagrant ssh command) by running ssh -p 2200 vagrant@127.0.0.1 with he only difference being that -p for port is lower case.

Filed Under: Tools

Copyright © 2025 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in