[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-11。"],[],[],null,["# Develop code using a local VS Code editor\n\nLearn how to open an SSH tunnel from your local machine\nto a workstation, and then use\n[VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview)\nsupport to connect to Cloud Workstations from your local VS Code editor.\n| **Tip:** For an in-browser experience, you can use the Cloud Workstations IDE [Code OSS for Cloud Workstations](/workstations/docs/base-editor-overview), which is based on the [Code-OSS](https://github.com/microsoft/vscode) open source project.\n\nBefore you begin\n----------------\n\nBefore you begin, make sure that you follow the steps for these tasks:\n\n1. Make sure that someone on your team has created a [workstation configuration](/workstations/docs/create-configuration).\n2. [Create and start your workstation](/workstations/docs/create-workstation).\n3. While you're in the Google Cloud console, copy the following information:\n\n 1. Project name and ID: click the project name in the Google Cloud menu bar and copy the ID in the **Project name and ID** dialog that opens.\n 2. Region\n 3. Cluster name\n 4. Configuration name\n4. From your local machine,\n [install the `gcloud` CLI](/sdk/docs/install).\n\n If you're running `gcloud` CLI for the first time, you may also\n need to run `gcloud auth login` to obtain credentials and\n `gcloud config set project `\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e to set your current\n project to the project ID you copied in the previous step.\n5. When using `ssh` for the first time, install a remote SSH extension so you\n can connect to a workstation from the VS Code editor through the\n Extension Marketplace or through the command palette.\n\n ### Extension Marketplace\n\n 1. Open your local VS Code editor application and then open the\n Extension Marketplace by selecting \n\n **Extensions** in the Activity bar.\n\n 2. Click **Install** to install the **Remote - SSH** extension.\n\n 3. Enter `remote ssh` in the search field, which opens the extension page\n for **Remote - SSH.**\n\n ### Command palette\n\n 1. To open the command palette, press \u003ckbd\u003eControl+Shift+P\u003c/kbd\u003e\n (or \u003ckbd\u003eCommand+Shift+P\u003c/kbd\u003e on macOS), or click\n **View** \\\u003e **Command Palette**.\n\n 2. Enter `ext install ms-vscode-remote.remote-ssh` to install the\n extension.\n\nOpen an SSH tunnel\n------------------\n\nOpen an SSH tunnel from your local machine to a workstation using the\n[`gcloud workstations start-tcp-tunnel`](/sdk/gcloud/reference/workstations/start-tcp-tunnel)\ncommand:\n\n1. In the Google Cloud console,\n go to the **Cloud Workstations** \\\u003e **Workstations** page.\n\n\n [Go to Workstations](https://console.cloud.google.com/workstations/list)\n\n \u003cbr /\u003e\n\n2. Click the workstation name to open the **Workstation details** page.\n\n3. In the following example, replace the placeholders for the\n workstation name, region (location), workstation cluster name, and\n workstation configuration name. Copy the values from the Workstation details\n panel into the placeholders marked with an\n editEdit icon.\n\n gcloud workstations start-tcp-tunnel \\\n --project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --region=\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e \\\n --cluster=\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e \\\n --config=\u003cvar translate=\"no\"\u003eCONFIG_NAME\u003c/var\u003e \\\n --local-host-port=:\u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e \\\n \u003cvar translate=\"no\"\u003eWORKSTATION_NAME\u003c/var\u003e 22\n\n See the\n [Before you begin](/workstations/docs/develop-code-using-local-vscode-editor#before_you_begin)\n section to find the project ID.\n\n The `--local-host-port=:`\u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e flag is optional.\n If you would like to specify a local port, replace\n \u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e with the local port number that you want\n to use. If you don't specify a local port, the system chooses an\n arbitrary, unused local port for you, and outputs a message with the port\n number so you know which local port it uses.\n4. After filling in the placeholders, click\n content_copy\n **Copy code sample** to copy the `gcloud` CLI command.\n\n5. Paste the command into your local terminal window and press \u003ckbd\u003eEnter\u003c/kbd\u003e\n to create the tunnel.\n\n When the command succeeds, a `Listening on port` message appears followed by\n the local port number.\n\n\nFor more details about each configuration flag, see\n[SSH tunnel](/workstations/docs/ssh-support)\nor\n[`start-tcp-tunnel`](/sdk/gcloud/reference/workstations/start-tcp-tunnel).\n\nConnect to a Cloud Workstations host\n------------------------------------\n\nFollow these steps to connect to a Cloud Workstations host:\n\n1. Open or return to the VS Code application.\n2. To launch **Remote - SSH** , click\n **Open a Remote Window** in the status bar.\n\n3. Select the **Connect to Host** option when the command palette opens.\n\n4. Enter `user@localhost:`\u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e, replacing\n \u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e with your local port number.\n\n The following example connects to local port `1025` by specifying\n `user@localhost:1025`.\n\n | **Note:** The host keys for the workstations change between sessions because workstations run on ephemeral VMs. Ensure that host key validation is disabled for the workstation configuration for this reason.\n5. If prompted to connect after you see the **Host Added** confirmation\n message, click **Connect**.\n\n The system might also prompt you to confirm the hash. If prompted, click\n **Continue**.\n6. A new VS Code editor opens and the VS Code status bar shows\n **SSH: localhost:** followed by the port number.\n\n You now have access to the files and language servers on your remote workstation,\n and you can build and run processes that run inside your workstation.\n\n The following example shows a VS Code editor window connected to\n Cloud Workstations through **SSH: localhost: 1025**.\n\n You can also go back to the Extensions Marketplace to install\n [Cloud Code](/code/docs)\n and other local VS Code extensions to help you\n build, run, and test your code."]]