LoginSignup
33
31

More than 3 years have passed since last update.

【正式リリース版】VS CodeのRemote DevelopmentでRaspberry Pi内のファイルを編集する

Posted at

はじめに

Raspberry PiでRemote Developmentを動作させる方法について記載します。
接続先のRaspberry Piを「リモート先」と記載しています。

動作環境

  • Visual Studio Code
    vscode_env.PNG

  • Raspberry Pi 3(armv7)

  • Raspbian 8.0

  • Remote Development 0.17.0

  • Remote - SSH 0.47.1

Remote Developmentとは

リモート先のファイルを編集するVS Code公式の拡張機能です。2019年10月にarmv7のRaspberry Pi対応が正式リリースされました。

以下のようにRaspberry Pi内のファイルを編集できます。
remote_develop_raspi_ex1.png

※VS Codeの拡張機能で「Remote VSCode」もありますが別物です。

準備

SSH configファイルを用意

Remote DevelopmentにはRaspberry Piと接続するためのSSH configファイルが必要です。
私は以下のURLを参考にSSH環境及びSSH configファイルを作成しました。
https://tool-lab.com/2013/11/raspi-key-authentication-over-ssh/

Windows環境では以下のパスのconfigファイルをRemote Developmentが参照します。

  • C:\Users\(ユーザー名)\.ssh\config
  • C:\ProgramData\ssh\ssh_config

拡張機能のインストール

VS Codeに以下の拡張機能をインストールします。

Remote Developmentを動かしてみる

1. VS CodeからSSH接続する

「><」が表示されたアイコンをクリックして「Remote-SSH: Connect to host..」をクリックし接続したいConfigを選択するとSSH接続できます。もしくは以下の画像のようにモニタアイコンをクリックすると接続できます。

remote_develop_raspi_ex2.png

その後、初回などの場合はvscode-serverがインストールされるのでしばらく待ちます。

2. リモート先のディレクトリを開く

「フォルダーを開く」ボタンを押下して、開きたいリモート先のディレクトリを選択してOKを押下します。
(「フォルダーを開く」は日本語の拡張機能追加時に表示される)

remote_develop_raspi_ex3.png

3. ファイル編集

通常のVS Codeのようにファイルやディレクトリを作成をしたり開いたりできます。
編集して保存した時にリモート先のファイルに編集内容が反映されます。
また、下のウィンドウよりリモート先のターミナル操作も出来ます。
remote_develop_raspi_ex4.png

参考

https://www.hanselman.com/blog/VisualStudioCodeRemoteDevelopmentOverSSHToARaspberryPiIsButter.aspx
https://github.com/microsoft/vscode-remote-release/issues/13
https://github.com/microsoft/vscode-remote-release/issues/103#issuecomment-497118857

33
31
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
33
31