0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VM のファイルをローカルにコピーする

Posted at

はじめに

本記事では、 SSH鍵の確認 → scp でファイル転送するところまで の手順をまとめます。

SSH鍵の確認(事前準備)

Vagrantfile があるディレクトリで以下を実行

vagrant ssh-config

すると、こんな出力が得られます👇

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  IdentityFile "C:/path/to/project/.vagrant/machines/default/virtualbox/private_key"

ここで 下記3つを確認

項目 使い方
HostName SSHの接続先 → 127.0.0.1
Port 使用ポート → 2222
IdentityFile これが SSH/ SCP に必要な秘密鍵のパス

scp を使ってファイルを転送する(本番)

下記コマンドを実行

scp -P <ポート番号> -i <秘密鍵へのパス> vagrant@<接続先>:<VM内のコピーしたいファイルのパス> <コピーしたファイルを出力する場所>

例)

scp -P 2222 -i C:/path/to/project/.vagrant/machines/default/virtualbox/private_key vagrant@127.0.0.1:/home/vagrant/sample.txt C:/Users/username/Desktop/

よくあるエラーと対処

エラー 原因 対処
Permission denied (publickey) 秘密鍵を指定していない -i <private_key> を付ける
No such file or directory ファイルパスが違う VM内で ls で確認
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?