Skip to content

Instantly share code, notes, and snippets.

@colindean
Last active November 21, 2023 03:27
Show Gist options
  • Save colindean/5213685 to your computer and use it in GitHub Desktop.
Save colindean/5213685 to your computer and use it in GitHub Desktop.
A quick way to transfer a file to the home directory on a Vagrant VM
#!/bin/sh
OPTIONS=`vagrant ssh-config | awk -v ORS=' ' '{print "-o " $1 "=" $2}'`
scp ${OPTIONS} "$@" || echo "Transfer failed. Did you use 'default:' as the target?"
#!/bin/bash
PORT=2222
if [ ${VAGPORT} ]; then
PORT=${VAGPORT}
fi
VAGRANT_GEM=$(dirname `gem which vagrant`)/..
VAGRANT_KEY=${VAGRANT_GEM}/keys/vagrant
chmod 600 ${VAGRANT_KEY}
ssh -i ${VAGRANT_KEY} -p ${PORT} vagrant@localhost
#need to test this:
#OPTIONS=`vagrant ssh-config | awk -v ORS=' ' '{print "-o " $1 "=" $2}'`;
#ssh ${OPTIONS} localhost
@sekoyo
Copy link

sekoyo commented Sep 21, 2015

Thanks @geedew easiest answer I've found

@nkuclassical
Copy link

Thanks @spyderman4g63 extremely easy way!

@pxwise
Copy link

pxwise commented May 10, 2016

@spyderman4g63 👍 thanks!!

@compositor
Copy link

I get Host directive not supported as a command-line option error.
Solution is here https://gist.github.com/geedew/11289350

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

@tangrufus
Copy link

For those who need sudo privilege, try $ vagrant sudo-rsync.

See: https://github.com/TypistTech/vagrant-sudo-rsync

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