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
Get IdentityFile and Port by using
vagrant ssh-config
scp -i IdentityFile_file -P Port vagrant@127.0.0.1:/file_dir dist_dir
e.g.
scp -i /Users/xxxxx/tmp/vagrant/centos_6.5/.vagrant/machines/default/virtualbox/private_key -P 2200 vagrant@127.0.0.1:/tmp/xxx .
You should read the manual page for scp
. The correct syntax is:
scp -P 2222 vagrant@127.0.0.1:/home/vagrant/devstack/local.conf .
The uppercase P is for "port". Lowercase is used to preserve modification times.
Additional tools like scp or cat may not be necessary. Frederick Henri covered it here.
Essentially, cp [file] /var/www/[your vm]/.vagrant
will copy the file to the .vagrant folder at your project root, where you can see and move the file in your desktop OS.
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).
As @SevenJ mentioned, ssh-config can provide all the info you need. But it's a lot easier to save it to a file and use that file, rather than constructing a complicated scp command. E.g.:
vagrant ssh-config > config.txt
scp -F config.txt default:/path/to/file .
Here I'm assuming your vagrant file doesn't override the machine name from "default". If it does, replace "default:" with ":".
This is a handy tool for anyone coming in via Google: Vagrant SCP