Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite wird beschrieben, wie Sie über die gcloud-Befehlszeile eine Verbindung zu Ihrer Workstation von einem lokalen Computer aus über SSH (oder ein anderes TCP-Protokoll) herstellen.
Cloud Workstations verwendet einen Tunnel, um TCP-Traffic zwischen einem Port auf Ihrem lokalen Computer und einem Port auf Ihrer Workstation weiterzuleiten, ohne Ihre Workstation offen im Internet zu präsentieren. Verbindungen werden mit Anmeldedaten aus der gcloud-Befehlszeile authentifiziert und gemäß den IAM-Richtlinien der Zielarbeitsstation autorisiert.
Sobald der TCP-Tunnel zwischen Ihrem lokalen Port und der Workstation hergestellt ist, können Sie ihn verwenden, um Traffic von einem SSH-Client, curl oder einer anderen Anwendung, die TCP verwendet, weiterzuleiten.
Cloud Workstations bietet den Befehl gcloud workstations ssh, mit dem der TCP-Tunnel eingerichtet und ein SSH-Client mit einem einzigen gcloud-CLI-Befehl ausgeführt wird.
Verwenden Sie für alle anderen Anwendungsfälle den Befehl gcloud workstations start-tcp-tunnel, um den TCP-Tunnel herzustellen, und führen Sie die Anwendung, die den Tunnel verwendet (z. B. curl), in einem separaten Terminal aus.
Über SSH eine Verbindung zur Workstation herstellen
Verwenden Sie den Befehl gcloud workstations ssh, um eine sichere SSH-Verbindung zu Ihrer Workstation herzustellen. Dadurch wird ein TCP-Tunnel gestartet und ein SSH-Client ausgeführt.
Klicken Sie auf content_copyCodebeispiel kopieren, um den Befehl in die Zwischenablage zu kopieren, und fügen Sie ihn dann in ein lokales Terminalfenster ein:
PROJECT_ID: die Google Cloud Projekt-ID für das Projekt, das die Workstation enthält. Wenn nichts angegeben ist, wird das aktuelle Projekt verwendet.
REGION: Die Region, in der sich der Cluster der Workstation befindet, z. B. us-central1.
CLUSTER_NAME: Der Name des Workstation-Clusters, der die Workstation enthält.
CONFIG_NAME: Der Name der Arbeitsstationskonfiguration, die diese Arbeitsstationen enthält.
WORKSTATION_PORT (Optional): Der Port auf der Workstation, an den der Traffic gesendet werden soll. Wenn nichts angegeben ist, wird Traffic an Port 22 gesendet. Alle vorkonfigurierten Cloud Workstations-Images enthalten einen SSH-Server, der auf dem Workstation-Port 22 ausgeführt wird.
LOCAL_PORT (optional): der Localhost-Port, von dem Traffic gesendet wird. Gültige Portnummern sind 1024 bis 65535. Wenn Sie das Flag --local-host-port weglassen oder den Port 0 angeben, wird automatisch ein nicht verwendeter Port ausgewählt.
WORKSTATION_NAME: Der Name der Arbeitsstation.
Optional: Wenn Sie Flags und Positionsparameter an die zugrunde liegende ssh-Implementierung übergeben möchten, hängen Sie sie nach einem doppelten Bindestrich (--) an den Befehl an.
TCP-Tunnel verwenden, um beliebigen TCP-Traffic an Ihre Workstation weiterzuleiten
Wenn Sie mit einer anderen TCP-Anwendung als ssh eine Verbindung zu einer Workstation herstellen möchten, verwenden Sie den Befehl gcloud workstations start-tcp-tunnel:
Führen Sie den folgenden gcloud-CLI-Befehl aus, um einen authentifizierten TCP-Tunnel zu erstellen.
Klicken Sie auf content_copyCodebeispiel kopieren, um den Befehl in die Zwischenablage zu kopieren, und fügen Sie ihn dann in ein lokales Terminalfenster ein:
PROJECT_ID: die Google Cloud Projekt-ID für das Projekt, das die Workstation enthält. Wenn nichts angegeben ist, wird das aktuelle Projekt verwendet.
REGION: Die Region, in der sich der Cluster der Workstation befindet, z. B. us-central1.
CLUSTER_NAME: Der Name des Workstation-Clusters, der die Workstation enthält.
CONFIG_NAME: Der Name der Workstation-Konfiguration, die diese Workstations enthält.
LOCAL_PORT (optional): der Localhost-Port, von dem Traffic gesendet wird. Gültige Portnummern sind 1024 bis 65535. Wenn Sie das Flag --local-host-port weglassen oder den Port 0 angeben, wird automatisch ein nicht verwendeter Port ausgewählt.
WORKSTATION_NAME: Der Name der Arbeitsstation.
WORKSTATION_PORT: Der Workstation-Port, an den der Traffic gesendet werden soll.
Vorkonfigurierte Cloud Workstations-Images enthalten einen SSH-Server, der auf dem Workstation-Port 22 ausgeführt wird.
Mit dem gcloud-CLI-Befehl wird ein Konnektivitätstest mit der Workstation durchgeführt, ein Tunnel geöffnet und dann eine Portnummer angezeigt:
Listening on port [LOCAL_PORT].
Der gesamte an localhost:LOCAL_PORT gesendete Traffic wird an die Workstation weitergeleitet. Der Port ist nur für Anwendungen zugänglich, die auf Ihrem lokalen Computer ausgeführt werden.
Lassen Sie die gcloud-Befehlszeile laufen und öffnen Sie ein weiteres Terminal, um die Anwendung auszuführen, die eine Verbindung zu Ihrer Workstation herstellt.
Wenn Sie beispielsweise einen Server auf Ihrer Workstation ausführen, der Port WORKSTATION_PORT bereitstellt, und Sie im vorherigen Schritt einen TCP-Tunnel erstellt haben, der Traffic zwischen Ihrem lokalen Port LOCAL_PORT und dem Workstation-Port WORKSTATION_PORT weiterleitet, können Sie curl auf Ihrem lokalen Computer ausführen, um eine Verbindung zum Server auf Ihrer Workstation herzustellen:
curl localhost:LOCAL_PORT
Hello, world!
Wenn Sie fertig sind, kehren Sie zum Terminal zurück, in dem Sie den TCP-Tunnel gestartet haben, und unterbrechen Sie die gcloud-Befehlszeile, indem Sie Strg+C drücken.
SSH-Server auf verschiedenen Ports verwenden
Benutzerdefinierte Container-Images können auch SSH-Server auf einem beliebigen Port verwenden. Damit Verbindungen über den gcloud-CLI-Tunnel unterstützt werden, müssen Sie benutzerdefinierte SSH-Server so konfigurieren, dass die Passwortauthentifizierung zulässig ist, und den Zielnutzer mit einem leeren Passwort festlegen.
Cloud Workstations verwendet Cloud IAM, um dafür zu sorgen, dass nur autorisierter Traffic an den SSH-Server gesendet wird.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-11 (UTC)."],[],[],null,["# SSH support\n\nThis page describes how to use the `gcloud` CLI to connect to your\nworkstation from a local machine using SSH (or any other TCP protocol).\n\nCloud Workstations uses a tunnel to forward TCP traffic between a port on your\nlocal machine and a port on your workstation without openly exposing\nyour workstation to the internet. Connections are authenticated using\ncredentials from the `gcloud` CLI and authorized according to the\ntarget workstation's IAM policies.\n\nOnce the TCP tunnel is established between your local port and the workstation,\nyou can use it to forward traffic from an SSH client, curl, or any other\napplication that uses TCP.\n\nFor convenience, Cloud Workstations provides the\n[`gcloud workstations ssh`](/sdk/gcloud/reference/workstations/ssh)\ncommand, which establishes the TCP tunnel and runs an SSH client with a\nsingle `gcloud` CLI command.\n\nFor all other use cases, use the\n[`gcloud workstations start-tcp-tunnel`](/sdk/gcloud/reference/workstations/start-tcp-tunnel)\ncommand to establish the TCP tunnel and run the application that will use the\ntunnel (for example, `curl`) in a separate terminal.\n| **Note:** All preconfigured Cloud Workstations images include an SSH server that runs on workstation port `22`.\n\nBefore you begin\n----------------\n\n1. If you don't already have a workstation to connect to,\n [set up a workstation](/workstations/docs/quickstart-set-up-workstations-console).\n\n2.\n\n\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the `gcloud` CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n \u003cbr /\u003e\n\n3. Make sure that you have the\n [Cloud Workstations User](/workstations/docs/access-control#workstations-user)\n IAM role on the workstation you will connect to.\n\n [Go to IAM](https://console.cloud.google.com/iam-admin/iam)\n\nConnect to your workstation using SSH\n-------------------------------------\n\nTo establish a secure SSH connection to your workstation, use the\n[`gcloud workstations ssh`](/sdk/gcloud/reference/workstations/ssh)\ncommand, which starts a TCP tunnel and runs an SSH client.\n\nTo copy the command to the copy-paste buffer, click\ncontent_copy\n**Copy code sample** and then paste the command into a local terminal window: \n\n gcloud workstations ssh \\\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 --port=\u003cvar translate=\"no\"\u003eWORKSTATION_PORT\u003c/var\u003e \\\n --local-host-port=localhost:\u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e \\\n \u003cvar translate=\"no\"\u003eWORKSTATION_NAME\u003c/var\u003e\n\nReplace the following values:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the Google Cloud project ID for the\n project containing the workstation. If omitted, the current project is\n used.\n\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the region where the workstation's cluster is\n located---for example, `us-central1`.\n\n- \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e: the name of the workstation cluster\n containing the workstation.\n\n- \u003cvar translate=\"no\"\u003eCONFIG_NAME\u003c/var\u003e: the name of the workstation configuration\n containing this workstations.\n\n- \u003cvar translate=\"no\"\u003eWORKSTATION_PORT\u003c/var\u003e (Optional): the port on the workstation\n to which traffic should be sent. If omitted, traffic will be sent to port\n `22`. All preconfigured Cloud Workstations images include an SSH server that runs\n on workstation port `22`.\n\n- \u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e (Optional): the localhost port from which\n traffic will be sent. Valid port numbers are `1024` to `65535`. If you omit\n the `--local-host-port` flag or specify a port of `0` an unused port is\n selected automatically.\n\n- \u003cvar translate=\"no\"\u003eWORKSTATION_NAME\u003c/var\u003e: the name of the workstation.\n\nOptional: To pass flags and positionals to the underlying `ssh`\nimplementation, append them to the command after a double-dash (`--`).\n\nUse a TCP tunnel to forward arbitrary TCP traffic to your workstation\n---------------------------------------------------------------------\n\nTo connect to a workstation using a TCP application other than `ssh`, use the\n[`gcloud workstations start-tcp-tunnel`](https://cloud.google.com/sdk/gcloud/reference/workstations/start-tcp-tunnel)\ncommand:\n\n1. Run the following `gcloud` CLI command to create an authenticated\n TCP tunnel.\n\n To copy the command to the copy-paste buffer, click\n content_copy\n **Copy code sample** and then paste the command into a local terminal window: \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=localhost:\u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e \\\n \u003cvar translate=\"no\"\u003eWORKSTATION_NAME\u003c/var\u003e \\\n \u003cvar translate=\"no\"\u003eWORKSTATION_PORT\u003c/var\u003e\n\n Replace the following values:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the Google Cloud project ID for the\n project containing the workstation. If omitted, the current project is\n used.\n\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the region where the workstation's cluster is\n located---for example, `us-central1`.\n\n - \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e: the name of the workstation cluster\n containing the workstation.\n\n - \u003cvar translate=\"no\"\u003eCONFIG_NAME\u003c/var\u003e: the name of the workstation\n configuration containing this workstations.\n\n - \u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e (Optional): the localhost port from which\n traffic will be sent. Valid port numbers are `1024` to `65535`. If you\n omit the `--local-host-port` flag or specify a port of `0` an unused\n port is selected automatically.\n\n - \u003cvar translate=\"no\"\u003eWORKSTATION_NAME\u003c/var\u003e: the name of the workstation.\n\n - \u003cvar translate=\"no\"\u003eWORKSTATION_PORT\u003c/var\u003e: the workstation port to which\n traffic should be sent.\n [Preconfigured Cloud Workstations images](/workstations/docs/preconfigured-base-images)\n include an SSH server that runs on workstation port `22`.\n\n2. The `gcloud` CLI command performs a connectivity test with the\n workstation, opens a tunnel, and then displays a port number:\n\n Listening on port [\u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e].\n\n All traffic sent to `localhost:`\u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e is forwarded to\n the workstation. The port is only accessible by applications running on your\n local computer.\n3. Leave the `gcloud` CLI running and open another terminal to run the\n application that connects to your workstation.\n\n For example, if you are running a server on your workstation that serves\n port \u003cvar translate=\"no\"\u003eWORKSTATION_PORT\u003c/var\u003e, and in the previous step you\n created a TCP tunnel that forwards traffic between your local port\n \u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e and the workstation port\n \u003cvar translate=\"no\"\u003eWORKSTATION_PORT\u003c/var\u003e, you could run `curl` on your local\n machine to connect to the server on your workstation: \n\n curl localhost:\u003cvar translate=\"no\"\u003eLOCAL_PORT\u003c/var\u003e\n Hello, world!\n\n4. When you are finished, return to the terminal where you started the TCP\n tunnel and interrupt the `gcloud` CLI by pressing\n \u003ckbd\u003eControl+C\u003c/kbd\u003e.\n\nUse SSH servers on different ports\n----------------------------------\n\n[Custom container images](/workstations/docs/custom-container-images)\ncan also use SSH servers on any port. To support connections from the\n`gcloud` CLI tunnel, you must configure custom SSH servers to allow\npassword authentication and set the target user with an empty password.\nCloud Workstations uses\n[Cloud IAM](/iam/docs/overview)\nto help ensure that only authorized traffic is sent to the SSH server.\n\nWhat's next\n-----------\n\n- [Set container environment variables in SSH sessions](/workstations/docs/customize-container-images#container_image_that_sets_container_environment_variables_in_ssh_sessions) for custom container images\n- [Enable X11 forwarding](/workstations/docs/customize-container-images#container_image_that_enables_x11_forwarding_for_ssh_sessions) for custom container images"]]