Sviluppare codice utilizzando un editor VS Code locale
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Scopri come aprire un tunnel SSH dalla tua macchina locale
a una workstation, quindi utilizza
VS Code Remote Development
per connetterti a Cloud Workstations dall'editor VS Code locale.
Prima di iniziare
Prima di iniziare, assicurati di seguire i passaggi per queste attività:
Nella Google Cloud console, copia le seguenti informazioni:
Nome e ID progetto: fai clic sul nome del progetto nella Google Cloud
barra dei menu e copia l'ID nella finestra di dialogo Nome e ID progetto che si apre.
Se esegui l'interfaccia a riga di comando gcloud per la prima volta, potresti anche dover eseguire gcloud auth login per ottenere le credenziali e gcloud config set project PROJECT_ID per impostare il progetto corrente sull'ID progetto che hai copiato nel passaggio precedente.
Quando utilizzi ssh per la prima volta, installa un'estensione SSH remota per poterti connettere a una workstation dall'editor di VS Code tramite il marketplace delle estensioni o la tavolozza dei comandi.
Marketplace di estensioni
Apri l'applicazione dell'editor VS Code locale e poi il Mercato delle estensioni selezionando Estensioni nella barra delle attività.
Fai clic su Installa per installare l'estensione Remote - SSH.
Inserisci remote ssh nel campo di ricerca per aprire la pagina dell'estensione per Remote - SSH.
Tavolozza comandi
Per aprire la tavolozza dei comandi, premi Control+Maiusc+P (o Comando+Maiusc+P su macOS) oppure fai clic su Visualizza>Tavolozza comandi.
Inserisci ext install ms-vscode-remote.remote-ssh per installare l'estensione.
Fai clic sul nome della workstation per aprire la pagina Dettagli workstation.
Nell'esempio seguente, sostituisci i segnaposto per il nome della workstation, la regione (posizione), il nome del cluster di workstation e il nome della configurazione della workstation. Copia i valori dal riquadro dettagli della stazione di lavoro nei segnaposto contrassegnati da un'icona di modifica.
Il flag --local-host-port=:LOCAL_PORT è facoltativo.
Se vuoi specificare una porta locale, sostituisci
LOCAL_PORT con il numero di porta locale che vuoi
utilizzare. Se non specifichi una porta locale, il sistema ne sceglie una
arbitraria e non utilizzata e visualizza un messaggio con il numero
della porta in modo che tu sappia quale porta locale viene utilizzata.
Dopo aver compilato i segnaposto, fai clic su
content_copyCopia esempio di codice per copiare il comando della CLI gcloud.
Incolla il comando nella finestra del terminale locale e premi Invio per creare il tunnel.
Se il comando ha esito positivo, viene visualizzato un messaggio Listening on port seguito dal numero di porta locale.
Per avviare Remoto - SSH, fai clic su Apri una finestra remota nella barra di stato.
Seleziona l'opzione Connetti all'host quando si apre la tavolozza dei comandi.
Inserisci user@localhost:LOCAL_PORT, sostituendo
LOCAL_PORT con il numero della porta locale.
L'esempio seguente si connette alla porta locale 1025 specificando
user@localhost:1025.
Se ti viene chiesto di effettuare la connessione dopo aver visualizzato il messaggio di conferma Host aggiunto, fai clic su Connetti.
Il sistema potrebbe anche chiederti di confermare l'hash. Se richiesto, fai clic su
Continua.
Si apre un nuovo editor VS Code e la barra di stato di VS Code mostra
SSH: localhost: seguito dal numero di porta.
Ora hai accesso ai file e ai server linguistici sulla tua workstation remota e puoi creare ed eseguire processi all'interno della workstation.
L'esempio seguente mostra una finestra dell'editor VS Code connessa a Cloud Workstations tramite SSH: localhost: 1025.
Puoi anche tornare al marketplace delle estensioni per installare Cloud Code e altre estensioni VS Code locali che ti aiuteranno a compilare, eseguire e testare il codice.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 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."]]