Remote-SSH プラグイン実行時にcould not to establish connection to エラー

Remote-SSH: Connect Host 実行時に失敗する

Visual Studio Codeの Remote-SSH プラグイン使用時に、could not to establish connection to “xxx”というダイアログが出て接続でないトラブルに見舞われた。

ログのウインドウを見ると、下記の通り、Windows 10(Windows 10 1903)の標準OpenSSHクライアントを使っていて、その際にsshのconfigファイルに”permissions”がないと言われて、止まっている。

[12:17:43.264] SSH Resolver called for "ssh-remote+xxx.xxx.xxx.jp", attempt 1
[12:17:43.264] SSH Resolver called for host: xxx.xxx.xxx.jp
[12:17:43.264] Setting up SSH remote "xxx.xxx.xxx.jp"
[12:17:43.288] Using commit id "26076a4de974ead31f97692a0d32f90d735645c0" and quality "stable" for server
[12:17:43.290] Testing ssh with ssh -V
[12:17:43.340] ssh exited with code: 0
[12:17:43.340] Got stderr from ssh: OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
[12:17:43.342] Running script with connection command: ssh -T -D 50829 xxx.xxx.xxx.jp bash
[12:17:43.344] Install and start server if needed
[12:17:43.346] Terminal shell path: C:\WINDOWS\System32\cmd.exe
> ;C:\WINDOWS\System32\cmd.exe

[12:17:43.430] Got some output, clearing connection timeout
[12:17:43.438] >
[12:17:43.460] > Bad owner or permissions on C:\\Users\\XXXXXXXXX/.ssh/config
>>>
[12:17:43.469] > プロセスが、存在しないパイプに書き込もうとしました。
>
[12:17:43.905] "install" terminal command done
[12:17:43.906] Install terminal quit with output: プロセスが、存在しないパイプに書き込もうとしました。
[12:17:43.906] Received install output: プロセスが、存在しないパイプに書き込もうとしました。
[12:17:43.906] Stopped parsing output early. Remaining text: プロセスが、存在しないパイプに書き込もうとしました。
[12:17:43.906] Failed to parse remote port from server output
[12:17:43.906] Resolver error:

解法

こちらの中盤に書いてあるように
sshのconfigファイルのパーミションを修正するツールを導入、パーミション変更をする。

管理者モードでPowershellを立ち上げて、下記を順に実行する。

> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process

> Install-Module -Force OpenSSHUtils -Scope AllUsers

> Repair-UserSshConfigPermission ~/.ssh/config
> Get-ChildItem ~\.ssh\* -Include "id_rsa","id_dsa" -ErrorAction SilentlyContinue | % {
Repair-UserKeyPermission -FilePath $_.FullName @psBoundParameters
}

しかし、ここも以下のようなエラーが出て、うまく行かないことがある。

PackageManagement\Install-Package : ファイル 'OpenSSHUtils.psd1' の Authenticode 署名が無効なため、モジュール 'OpenSSHUtils' をイン
ストールまたは更新できません。
発生場所 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 文字:21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package]、Exception
+ FullyQualifiedErrorId :
InvalidAuthenticodeSignature,ValidateAndGet-AuthenticodeSignature,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

上記の場合、証明書のチェックを外すために、2行目のInstall-Module で-SkipPublisherCheckオプションを指定して再実行。

Install-Module -Force OpenSSHUtils -Scope AllUsers -Verbose -SkipPublisherCheck

ここまでうまく行ったら、再度、Repair-UserSsshConfigPermission の部分からやり直すと良い。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

20 − 4 =