Skip to content

Instantly share code, notes, and snippets.

Last active July 22, 2017 15:16
  • Star 7 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save geedew/11289350 to your computer and use it in GitHub Desktop.
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
Copy link

geedew commented Apr 25, 2014

Copy link

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}'`

Copy link

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