WSLでvagrant up した VM に vagrant ssh ではなく 通常のsshで接続する
大まかな手順
chmodでパーミッションを変更できるように
WSLでmetadataを扱えるようにする
WSLでmetadataを扱えるようにする
/etc/wsl.conf
というファイルを無ければ作成し、
metadataを扱えるようにする記述を書き加える。
下記を実行する。
sudo bash -c 'cat << EOF >> /etc/wsl.conf [automount] options = "metadata" EOF'
ファイルを作成したら一度ログアウトして入り直す。
参考 qiita.com
.ssh/config に vagrant ssh-config の情報を書き込み修正する
vagrant ssh-config
を実行するとsshの情報が出てくる。
$ vagrant ssh-config Host default HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile F:/virtual_machines/vagrant_home/boxes/ubuntu18/0/virtualbox/vagrant_private_key IdentitiesOnly yes LogLevel FATAL
これを~/.ssh/config
に追記すればよいのだが
IdentityFile
のパスがWindowsのパスになっているので、
/mnt/c/
のような形に書き直す必要がある。
ホスト名も必要に応じて書き換える。
まずは vagrant ssh-config
を ~/.ssh/config
に追記
$ vagrant ssh-config >> ~/.ssh/config
次に ~/.ssh/config
を修正。
最終的な~/.ssh/config
は下記のようにした。
Host my_ubuntu18 HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /mnt/f/virtual_machines/vagrant_home/boxes/ubuntu18/0/virtualbox/vagrant_private_key IdentitiesOnly yes LogLevel FATAL
.ssh/config と公開鍵のパーミッションを700にする
chmod 700 ~/.ssh/config chmod 700 /mnt/f/virtual_machines/vagrant_home/boxes/ubuntu18/0/virtualbox/vagrant_private_key
ls コマンドなどでパーミッションが変更されているか確認する。
問題なければ ssh my_ubuntu18
のようにして接続確認する。