2019/07/04 12:14 追記
Remote拡張で新たなウィンドウが起動された場合、そのウィンドウ内ではsettings.jsonの ${env: <var>}
が展開されず、この文字列のままPATHに設定されてしまうことが判明。この結果、ウィンドウ内でSSHが使用できず接続に失敗する。
どうにもできないので、この記事のやり方は非推奨。2019/07/04現在、VSCode Insiders (バージョン: 1.36.0-insider) ではRemote拡張の設定でSSHコマンドへのパス指定が実装されているため、これを利用してしまうのが手っ取り早そう。リリース版 (バージョン: 1.35.1) にはこの設定は無し。
追記: リリース版 (バージョン: 1.36.0) からssh.exeへのパス指定が追加されていることを確認。
Windows 10にて、普段git-bashからVisual Studio Codeを起動して作業しているが、その際VSCodeへgit-bashからPATHが渡され、VSCode側の認識するssh.exeがgit-bash側のものとWindows側のもの2種類が存在してしまっていた。
PS C:\Users\tofu\git\musashino205\openwrt> cmd Microsoft Windows [Version 10.0.18362.175] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\tofu\git\musashino205\openwrt>path PATH=C:\Users\tofu\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\tofu\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\Microsoft VS Code\bin;C:\Program Files (x86)\Poedit;D:\Compiler\go\bin;D:\Compiler\GOPATH\bin;C:\Users\tofu\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl C:\Users\tofu\git\musashino205\openwrt>where ssh.exe C:\Program Files\Git\usr\bin\ssh.exe C:\Windows\System32\OpenSSH\ssh.exe C:\Users\tofu\git\musashino205\openwrt>
この結果、Remoting (SSH)などでgit-bash側のssh.exeが使用され、Windows側のssh-agentに登録した認証情報を使用して自動的にログインできず、毎回パスワードを聞かれて非常に面倒だった。
大体対処できたのでメモ。
- Windowsの環境変数を追加登録
- Windowsの環境変数を登録。ユーザー環境変数で問題ない。
名前はVSCPATH
などとし、値は%PATH%
。 - settings.jsonを編集
- VSCodeのsettings.jsonを開き、以下を追加して保存(環境変数名は適宜合わせること)
"terminal.integrated.env.windows": { "PATH": "${env:VSCPATH}" }
${env:<variable>}
は環境変数を読み取って代入するもの。
以上。
PS C:\Users\tofu\git\musashino205\openwrt> cmd Microsoft Windows [Version 10.0.18362.175] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\tofu\git\musashino205\openwrt>path PATH=C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\dotnet\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files (x86)\Poedit;D:\Compiler\go\bin;D:\Compiler\GOPATH\bin;C:\Users\tofu\AppData\Local\Microsoft\WindowsApps; C:\Users\tofu\git\musashino205\openwrt>where ssh.exe C:\Windows\System32\OpenSSH\ssh.exe C:\Users\tofu\git\musashino205\openwrt>