やりかた
至って簡単。Chocolatyというアプリケーション管理ソフト(apt-getやyumみたいなものです)をインストールして、Chocolaty経由でOpenSSHをインストールするだけです。SSHが入ればvagrant ssh
ができるようになります。
Chocolatyのインストール
PowerShellは管理者権限で立ち上げて、以下のコマンドでインストール。簡単。
PS C:\> Set-ExecutionPolicy RemoteSigned
PS C:\> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
一行目はPowerShellのスクリプト実行ポリシーを変更しています。ローカルのスクリプトは実行可能に、且つリモートのスクリプトは署名付であれば実行可能にしています。
OpenSSHのインストール
以下のコマンドで一発。
cinst openssh
こんなメッセージがでると思います。
Chocolatey (v0.9.8.23) is installing 'openssh' and dependencies. By installing you accept the license for 'openssh' and
each dependency you are installing.
______ openssh v5.3.1.2 ______
Downloading openssh 32 bit (http://switch.dl.sourceforge.net/project/opensshwindows/OpenSSH%20for%20Windows/5.3/2010-02-
15%20rev%202/Release/OpenSSHWindows53p1-2.msi) to C:\Users\xxxxxx\AppData\Local\Temp\chocolatey\openssh\opensshInstall.msi
Installing openssh...
Elevating Permissions and running msiexec /i "C:\Users\xxxxxx\AppData\Local\Temp\chocolatey\openssh\opensshInstall.msi" /q
uiet . This may take awhile, depending on the statements.
openssh has been installed.
openssh has finished successfully! The chocolatey gods have answered your request!
Finished installing 'openssh' and dependencies - if errors not shown in console, none detected. Check log for errors if
unsure.
Reading environment variables from registry. Please wait... Done.
PATH通す
インストール成功したらパスを通します。普通にPATH通してもいいですし、PowerShellの$profileに記述してもいいです。
$profile
を編集する場合は、まず以下のコマンドでprofileファイルを開きます。
PS C:\> notepad $profile
一番最後の行に下記を追加。
$Env:Path += ";C:\Program Files (x86)\OpenSSH for Windows\bin\"
あとは保存すれば、PowerShellが立ち上がる度に、$profileが読み込まれ環境変数に、上記で追加したディレクトリが設定されます。
あれ、動かない?
vagrant sshする
一通り設定が終わったらPC再起動の上、vagrant up
vagrant ssh
してみてください。上手くいくと思います。
補足
Chocolatyは非常に便利です。Chocolaty経由でインストールできるソフトが以下のURLにいろいろ掲載されているので、興味あれば是非ご覧ください。
Chocolaty packages
https://chocolatey.org/packages