The way to scp between host machine and guest machine on Vagrant

When I was coding certain program to output CSV file running on Vagrant, I encountered the case that I wanted to transfer this CSV on guest machine to host machine. This is a memo to scp to transfer files among them.

On host machine.
$vagrant ssh-config
Host hostname
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /usr/local/var/hogehoge/.vagrant/machines/hostname/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardAgent yes
With this command, you can confirm config of OpenSSH to connect to guest machine.

Then output this config on a file.
$ vagrant ssh-config > ssh.config

When you want to transfer files from guest machine to host machine, you can scp like this.
$ scp -F ssh.config vagrant@hostname:/path/to/file/on/guest /path/to/transfer/on/host
If you liked this article

Let's subscribe the updates of Scuti!
Share on Google Plus

About Tomohide Kakeya

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment


Post a Comment