Mengembangkan kode menggunakan editor VS Code lokal
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Pelajari cara membuka tunnel SSH dari mesin lokal Anda
ke workstation, lalu gunakan dukungan
VS Code Remote Development
untuk terhubung ke Cloud Workstation dari editor VS Code lokal Anda.
Sebelum memulai
Sebelum memulai, pastikan Anda mengikuti langkah-langkah untuk tugas berikut:
Jika menjalankan gcloud CLI untuk pertama kalinya, Anda mungkin juga
perlu menjalankan gcloud auth login untuk mendapatkan kredensial dan
gcloud config set project PROJECT_ID untuk menetapkan project saat ini
ke project ID yang Anda salin di langkah sebelumnya.
Saat menggunakan ssh untuk pertama kalinya, instal ekstensi SSH jarak jauh agar Anda
dapat terhubung ke workstation dari editor VS Code melalui
Extension Marketplace atau melalui palet perintah.
Extensions Marketplace
Buka aplikasi editor VS Code lokal Anda, lalu buka
Extension Marketplace dengan memilih Extensions di panel Aktivitas.
Klik Instal untuk menginstal ekstensi Remote - SSH.
Masukkan remote ssh di kolom penelusuran, yang akan membuka halaman ekstensi untuk Remote - SSH.
Palet perintah
Untuk membuka palet perintah, tekan Control+Shift+P
(atau Command+Shift+P di macOS), atau klik
View>Command Palette.
Masukkan ext install ms-vscode-remote.remote-ssh untuk menginstal ekstensi.
Klik nama workstation untuk membuka halaman Workstation details.
Pada contoh berikut, ganti placeholder untuk nama workstation, region (lokasi), nama cluster workstation, dan nama konfigurasi workstation. Salin nilai dari panel detail Workstation ke placeholder yang ditandai dengan ikon Edit edit.
Flag --local-host-port=:LOCAL_PORT bersifat opsional.
Jika Anda ingin menentukan port lokal, ganti
LOCAL_PORT dengan nomor port lokal yang ingin
Anda gunakan. Jika Anda tidak menentukan port lokal, sistem akan memilih
port lokal arbitrer yang tidak digunakan untuk Anda, dan menampilkan pesan dengan nomor
port sehingga Anda tahu port lokal mana yang digunakan.
Setelah mengisi placeholder, klik
content_copyCopy code sample untuk menyalin perintah CLI gcloud.
Tempelkan perintah ke jendela terminal lokal Anda, lalu tekan Enter
untuk membuat tunnel.
Jika perintah berhasil, pesan Listening on port akan muncul, diikuti dengan
nomor port lokal.
Untuk mengetahui detail selengkapnya tentang setiap flag konfigurasi, lihat
SSH tunnel
atau
start-tcp-tunnel.
Menghubungkan ke host Cloud Workstations
Ikuti langkah-langkah berikut untuk terhubung ke host Cloud Workstations:
Buka atau kembali ke aplikasi VS Code.
Untuk meluncurkan Remote - SSH, klik Open a Remote Window di status bar.
Pilih opsi Connect to Host saat palet perintah terbuka.
Masukkan user@localhost:LOCAL_PORT, dengan mengganti
LOCAL_PORT dengan nomor port lokal Anda.
Contoh berikut terhubung ke port lokal 1025 dengan menentukan
user@localhost:1025.
Jika diminta untuk terhubung setelah Anda melihat pesan konfirmasi Host Added, klik Connect.
Sistem juga mungkin meminta Anda untuk mengonfirmasi hash. Jika diminta, klik
Lanjutkan.
Editor VS Code baru akan terbuka dan status bar VS Code akan menampilkan
SSH: localhost: diikuti dengan nomor port.
Sekarang Anda memiliki akses ke file dan server bahasa di workstation jarak jauh,
dan Anda dapat mem-build dan menjalankan proses yang berjalan di dalam workstation.
Contoh berikut menunjukkan jendela editor VS Code yang terhubung ke
Cloud Workstation melalui SSH: localhost: 1025.
Anda juga dapat kembali ke Extensions Marketplace untuk menginstal Cloud Code dan ekstensi VS Code lokal lainnya untuk membantu Anda mem-build, menjalankan, dan menguji kode.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-11 UTC."],[],[],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."]]