How to copy file from a Vagrant machine to localhost

geeks picture geeks · Sep 5, 2015 · Viewed 35.2k times · Source

I want to copy a local file from a Vagrant machine to my localhost, but I am getting an error message:

ssh: connect to host 127.0.0.1 port 22: Connection refused.

[user@localhost ceil]$ scp -p 2222 [email protected]:/home/vagrant/devstack/local.conf .
cp: cannot stat ‘2222’: No such file or directory
ssh: connect to host 127.0.0.1 port 22: Connection refused

I also tried using using localhost but still got the same error.

Answer

Jace Browning picture Jace Browning · Jul 12, 2016

Another option is cat the files to something local:

vagrant ssh -c "sudo cat /home/vagrant/devstack/local.conf" > local.conf

This should also work for files that require root permissions (something the vagrant SCP plugin doesn't seem to support).