> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs-staging.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 通过 SSH 使用 Visual Studio Code 进行开发

本指南将引导您如何从本地计算机使用 Visual Studio Code (VS Code) 通过 SSH 连接到您的开发板（例如运行 Ubuntu 的 RB3 Gen-2）。

### 前提条件

* 开发板已安装更新后的 Ubuntu 镜像：
  * [Qualcomm Dragonwing RB3 Gen 2 Vision Kit](/zh/devices/rb3-gen2-vision-kit)
  * [IQ-9075 EVK](/zh/devices/iq9075-evk/setup)
* 开发板已连接到互联网。

### 步骤 1 — 启用 SSH / 查找 IP 地址

1. 使用串口连接到设备，参见 [Qualcomm 文档：在设备上配置 Ubuntu](https://docs.qualcomm.com/bundle/publicresource/topics/80-90441-1/Use_Ubuntu_on_RB3_Gen2_3.html)（面向 RB3 的文档，但同样适用于 Rubik Pi 3）。
2. 通过控制台登录，默认用户名为 `ubuntu`，默认密码也是 `ubuntu`。
3. 确保网络已设置（以太网或 Wi-Fi）。
4. 查找开发板的 IP 地址。例如通过：

   ```
   sudo apt update && sudo apt install -y net-tools
   ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
   # 192.168.1.253
   ```

### 步骤 2 — 在 VS Code 中安装/启用 Remote ‑ SSH 扩展

在您的**本地**机器上：

1. 打开 VS Code。
2. 前往扩展（Extensions）。
3. 搜索 **Remote ‑ SSH**（Microsoft 出品）并安装。

### 步骤 3 — 在 VS Code 中将开发板添加为 SSH 主机

1. 在 VS Code 中打开**命令面板**（F1，macOS 上为 Command+Shift+P，Windows/Linux 上为 Ctrl+Shift+P）。

2. 运行 `Remote‑SSH: Add New SSH Host...`

3. 输入 SSH 连接字符串，例如：

   ```
   ubuntu@board-ip-address
   ```

   *可选：* 如果您使用密钥，可以包含身份文件：

   ```
   ssh -i ~/.ssh/id_rsa_board user@board-ip-address
   ```

4. 选择要使用的 SSH 配置文件（通常为 `~/.ssh/config`）。VS Code 将为您的开发板插入一个条目。

   示例配置片段：

   ```
   Host my-board
       HostName 192.168.1.100
       User ubuntu
       IdentityFile ~/.ssh/id_rsa_board
   ```

### 步骤 4 — 通过 VS Code 连接到开发板

1. 在 VS Code 中，再次打开命令面板 → `Remote‑SSH: Connect to Host...`
2. 选择您的主机（例如 `ubuntu@board-ip-address` 或您在 SSH 配置中指定的名称）。
3. 如有提示，选择远程主机的平台。
4. 稍等片刻后，VS Code 将自动在开发板上安装 **VS Code Server**。状态会显示在底部状态栏中。
5. 连接后，您可以使用 **File → Open Folder...** 浏览开发板上的文件、打开终端（这些终端将在开发板上运行），并根据需要在远程主机上安装扩展。

### 故障排查

* **VS Code Server 占用过多内存：** 在远程主机上运行过多 VS Code 扩展可能消耗大量内存，导致内存不足（OOM）错误和随机的网络断连
  * **解决方案：** 在远程主机上禁用或有选择地启用扩展，以减少内存使用

* **SSH 连接失败：** 开发板无法访问 / IP 错误 / SSH 未运行
  * **解决方案：** 检查网络，从终端运行 `ssh ubuntu@IP`，[通过串口连接](https://docs.qualcomm.com/bundle/publicresource/topics/80-90441-1/Use_Ubuntu_on_RB3_Gen2_3.html)验证开发板的网络工具已更新且正常工作，例如

    ```
    sudo apt update && sudo apt install -y net-tools
    ifconfig
    ```

* **主机平台检测不正确：** VS Code 猜测错误（例如 ARM 与 x86）
  * **解决方案：** 在 VS Code 设置中手动设置 `remote.SSH.remotePlatform`

### 可选：使用基于 SSH 密钥的认证

为避免输入密码：

1. 如果还没有 SSH 密钥对，在本地机器上生成一个：

   ```
   ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_board
   ```

2. 将公钥添加到您的开发板：

   ```
   ssh-copy-id -i ~/.ssh/id_rsa_board.pub user@board-ip-address
   ```

3. 确认您可以在*不*输入密码的情况下通过 SSH 登录。

4. 更新您的 VS Code SSH 配置以引用此密钥（如步骤 3 所述）。
