2015/09/08

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
  HostName 127.0.0.1
  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


0 件のコメント:

コメントを投稿

Related Posts Plugin for WordPress, Blogger...