0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrant上にローカルからファイルをコピー(scp)

Last updated at Posted at 2020-03-16

ファイルのコピー

コマンドの実行場所はVagrant上ではなく、ローカルで実行。

ローカルからVagrant上へコピーの場合
$ scp /Users/user-name/Desktop/hoge.txt vagrant@web1:/www/file/

【構文】scp コピー元パス vagrant@VMホスト名:コピー先vagrant上のパス

↑↑これでローカルの「/Users/user-name/Desktop/hoge.txt」を、
Vagrant(web1バーチャルマシン)上の
/www/file/」ディレクトリにコピーする。

Vagrant上からローカルへコピーの場合
$ scp vagrant@web1:/www/file/hoge.txt /Users/user-name/Desktop/

VMホスト名はVagrantfileのvm.hostnameを参照。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.define "default" do |web1|
    web1.vm.box = "mvbcoding/awslinux"
    web1.vm.hostname = "web1"
    web1.vm.network "private_network", ip: "xxx.xxx.xxxx"
  end

ディレクトリのコピー

-r オプションをつけると、ディレクトリごとscpできる。

hogeディレクトリをvagrant上にコピー
$ scp -r /Users/user-name/Desktop/hoge vagrant@web1:/www/file/fuga/

以上。

0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?