LoginSignup
40
41

More than 3 years have passed since last update.

VS Code Remote Development SSHセットアップ中にハマったこと

Last updated at Posted at 2019-09-14

試した環境

  • クライアント
    • Windows 10 Pro: ver. 1903
    • Visual Studio Code:
      • Version: 1.38.1 (system setup)
      • Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
      • Date: 2019-09-11T13:35:15.005Z
      • Electron: 4.2.10
      • Chrome: 69.0.3497.128
      • Node.js: 10.11.0
      • V8: 6.9.427.31-electron.0
      • OS: Windows_NT x64 10.0.18362
    • Visual Studio Code Remote - SSH: ver. 0.46.0
    • ssh -V: OpenSSH_7.9p1, OpenSSL 1.1.1b 26 Feb 2019
      • ※Windows 10標準のOpenSSHではなく、MSYS2のOpenSSHを使用しています。
  • サーバー
    • Debian GNU/Linux: ver. 9.11
    • ssh -V: OpenSSH_7.4p1 Debian-10+deb9u7, OpenSSL 1.0.2s 28 May 2019

前提

クライアントからサーバーに、下記のコマンドでログインできること

ハマったところ1: remote.SSH.configFileが設定されてなければ読んでくれない?

初期設定時に「Select SSH configuration file」などと聞かれたので、従来から使っていたC:\Users\<クライアントのユーザー名>\.ssh\configを指定すると、指定したファイルが開かれたので、

Host <サーバーのホスト名>
    HostName <サーバーのホスト名>
    User <サーバーで使用するユーザー名>
    IdentityFile C:\Users\<クライアントのユーザー名>\.ssh\id_rsa

などと書いて「TARGETS (SSH)」に表示された<サーバーのホスト名>をダブルクリックすると、別ウィンドウで接続先のサーバー向けのVS Codeが起動... したんですが、すぐに「Could not establish connection to "<サーバーのホスト名>".」というエラーが出てしまいました。

Could not establish connection

ひとまず❎を押してウィンドウ下部にある「OUTPUT」に書いてある、ログっぽい文字列を確認したところ

[05:28:19.182] > <クライアントのユーザー名>@<サーバーのホスト名>: Permission denied (publickey,gssapi-keyex,gssapi-with-m
> ic)

と表示されていました。

ssh_configUser <サーバーで使用するユーザー名>と指定しているにもかかわらず、それが使用されず、代わりにデフォルトの値として<クライアントのユーザー名>が使われてしまっているみたいです。

どうしたものかとVS Code Remote Development SSHの設定項目を確認したところ、「Remote.SSH: Config File」なる設定項目(Setting ID: remote.SSH.configFile)が。

こちらに C:\Users\<クライアントのユーザー名>\.ssh\configを書いて再度接続すると、無事接続詞に行ったのですが、今度は別のエラーになりました。

ハマったところ2: 「Could not fetch remote environment」

今度は接続はできたのですが、「Could not fetch remote environment」とか「Failed to connect to the remote extension host server (Error: Time limit reached)」なるエラーが。

Could not fetch remote environment

VS Codeのウィンドウを見る限りそれ以上手がかりはなかったので、ログを漁ってみました。

するとC:\Users\<クライアントのユーザー名>\AppData\Roaming\Code\logsなるディレクトリーに、VS Codeを起動した時刻ごとにディレクトリーが1つ作られていました。

保存されるパスは起動した時刻などによって変わるようですが、私の場合C:\Users\<クライアントのユーザー名>\AppData\Roaming\Code\logs\20190914T141942\exthost4\output_logging_20190914T155257\1-Remote - SSH.logというファイルに、エラーの原因とおぼしきメッセージが書かれていました。

... 省略 ..
[06:52:59.242] [Forwarding server 57546] Got connection 1
[06:52:59.242] [Forwarding server 57546] Got connection 2
[06:52:59.252] > channel 3: open failed: administratively prohibited: open failed
[06:52:59.252] >
[06:52:59.253] Failed to set up socket for dynamic port forward to remote port 41075: Socket closed. Is the remote port correct?
... 省略 ..

このうち、administratively prohibited: open failedvscode-remote-releaseのissueを探してみると、下記のissueが見つかりました。

Channel 4: open failed: connect failed: Connection refused · Issue #773 · microsoft/vscode-remote-release

ドンピシャ🎯ですね(他にもよく似たissueが報告されています。原因もそれぞれバラバラかも知れません)。

長々とスクロールしてこちらのコメントに書いてあったStackExchangeの回答曰く、sshd_configを書き換えろ、とのこと。

そこで/etc/sshd_configを編集してAllowTcpForwardingPermitOpenという設定項目を次のように書き換えました。

AllowTcpForwarding yes
PermitOpen any

書き換えて保存したらsshdの再起動をお忘れなく:

$ sudo systemctl restart sshd

再度接続したところ、無事利用できました。🎉

これから詳しく使ってみます💪

なんでもLanguage Serverもサーバー側にインストールされたものが使われるそうなので、クライアントが非力なマシンでも快適に編集できそうでいいですね!

本文で言及のなかった参考ページ

40
41
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
40
41