Create a gist now

Instantly share code, notes, and snippets.

@geedew /vagrant-scp
Last active Jul 22, 2017

What would you like to do?
Copying files to a Vagrant VM from host
# Change these settings to match what you are wanting to do
OPTIONS=`vagrant ssh-config | awk -v ORS=' ' '{print "-o " $1 "=" $2}'`
scp ${OPTIONS} $FILE vagrant@$SERVER:$PATH

geedew commented Apr 25, 2014

guibog commented Sep 10, 2014

Hi, I got a "Host directive not supported as a command-line option" with Vagrant 1.4.3, had to tweak a bit:

OPTIONS=`vagrant ssh-config | grep -v '^Host ' | awk -v ORS=' ' '{print "-o " $1 "=" $2}'`

mykter commented Nov 30, 2014

To remove a trailing empty "-o = ", prepend the awk string with NF to filter out the blank line:

OPTIONS=`vagrant ssh-config | grep -v '^Host ' | awk -v ORS=' ' 'NF{print "-o " $1 "=" $2}'`

As the hostname and user are specified via the ssh config options, they don't need to be specified again. To copy a file from the host to a Vagrant VM:


to copy a file from a Vagrant VM to the host:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment