Ce document explique comment se connecter à des instances de machines virtuelles (VM) Linux disposant d'adresses IP externes à l'aide de clés SSH. Pour savoir comment vous connecter à des VM qui ne possèdent pas d'adresse IP externe, consultez la page Options de connexion pour les VM internes uniquement. Pour savoir comment vous connecter à des VM Linux à l'aide de certificats SSH, consultez Exiger des certificats SSH pour les VM avec connexion au système d'exploitation.
Pour en savoir plus sur le fonctionnement des connexions SSH dans Compute Engine, y compris la configuration et le stockage de clés SSH, consultez Connexions SSH aux VM Linux.
Avant de commencer
-
Si ce n'est pas déjà fait, configurez l'authentification.
L'authentification est le processus permettant de valider votre identité pour accéder aux services et aux API Trusted Cloud by S3NS .
Pour exécuter du code ou des exemples depuis un environnement de développement local, vous pouvez vous authentifier auprès de Compute Engine en sélectionnant l'une des options suivantes :
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
Installez la Google Cloud CLI, puis connectez-vous à la gcloud CLI avec votre identité fédérée. Après vous être connecté, initialisez Google Cloud CLI en exécutant la commande suivante :
gcloud init
- Set a default region and zone.
Systèmes d'exploitation compatibles
Ces méthodes de connexion sont compatibles avec toutes les images Linux publiques disponibles sur Compute Engine. Pour les images Fedora CoreOS, vous devez configurer l'accès SSH afin de pouvoir utiliser ces méthodes.
Se connecter à des VM
Pour vous connecter à une VM, suivez la procédure décrite dans l'un des onglets ci-dessous.
Console
Connectez-vous à des VM à l'aide de SSH-in-Browser depuis la consoleTrusted Cloud en procédant comme suit :
- In the Trusted Cloud console, go to the VM instances page.
- In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to.
gcloud
Connectez-vous à une VM à l'aide de SSH en exécutant la commande
gcloud compute ssh
:Exécutez la commande suivante :
gcloud compute ssh --project=PROJECT_ID --zone=ZONE VM_NAME
Remplacez les éléments suivants :
PROJECT_ID
: ID du projet contenant la VMZONE
: nom de la zone dans laquelle se trouve la VMVM_NAME
: nom de la VM
Si vous avez défini les propriétés par défaut de Google Cloud CLI, vous pouvez omettre les options
--project
et--zone
de cette commande. Exemple :gcloud compute ssh VM_NAME
- Ajoutez une clé SSH à la VM si vous ne l'avez pas déjà fait.
Dans la console Trusted Cloud , accédez à la page Instances de VM et recherchez l'adresse IP externe de la VM à laquelle vous souhaitez vous connecter.
- Ouvrez un terminal sur votre poste de travail.
Connectez-vous à la VM en exécutant la commande suivante :
ssh -i PATH_TO_PRIVATE_KEY USERNAME@EXTERNAL_IP
Remplacez les éléments suivants :
PATH_TO_PRIVATE_KEY
: chemin d'accès au fichier de clé SSH privée correspondant à la clé publique que vous avez ajoutée à la VM.USERNAME
: nom d'utilisateur est celui que vous avez spécifié lorsque vous avez créé la clé SSH.-
EXTERNAL_IP
: adresse IP externe de la VM.
- Ajoutez une clé SSH à la VM si vous ne l'avez pas déjà fait.
- Si l'application PuTTY n'est pas déjà installée sur votre poste de travail, téléchargez les fichiers de package PuTTY.
Dans la console Trusted Cloud , accédez à la page Instances de VM et recherchez l'adresse IP externe de la VM à laquelle vous souhaitez vous connecter.
- Ouvrez l'application PuTTY. Une fenêtre de configuration de connexion s'affiche.
Dans le champ
Host Name
, saisissez le nom d'utilisateur associé à la clé SSH et l'adresse IP externe de la VM à laquelle vous souhaitez vous connecter. Utilisez le format suivant :USERNAME@EXTERNAL_IP
Remplacez les éléments suivants :
USERNAME
: nom d'utilisateur est celui que vous avez spécifié lorsque vous avez créé la clé SSH.-
EXTERNAL_IP
: adresse IP externe de la VM.
- Dans le menu Catégorie, accédez à Connexion > SSH > Auth.
- Dans le champ Private key file for authentication (Fichier de clé privée pour l'authentification), sélectionnez le fichier de clé SSH privée correspondant à la clé publique que vous avez ajoutée à la VM.
- Cliquez sur Open (Ouvrir) pour vous connecter à la VM.
Ajoutez une clé SSH à la VM si vous ne l'avez pas déjà fait.
Si vous ne l'avez pas déjà fait, installez Secure Shell sur votre Chromebook ou dans le navigateur Chrome.
Dans la console Trusted Cloud , accédez à la page Instances de VM et recherchez l'adresse IP externe de la VM à laquelle vous souhaitez vous connecter.
Ouvrez Secure Shell dans une barre d'adresse de l'onglet du navigateur Chrome en procédant comme suit :
- Tapez
ssh
. - Appuyez sur la touche
Space
. - Appuyez sur la touche
Enter
.
- Tapez
Cliquez sur [Nouvelle connexion].
Dans le champ nom d'utilisateur, saisissez votre nom d'utilisateur. Si vous gérez vos clés SSH dans les métadonnées, le nom d'utilisateur est celui que vous avez spécifié lorsque vous avez créé la clé SSH. Pour les comptes OS Login, le nom d'utilisateur est défini dans votre profil Google. Par exemple,
cloudysanfrancisco_example_com
oucloudysanfrancisco
.Dans le champ nom d'hôte, saisissez l'adresse IP externe de la VM.
Dans le champ Identité, cliquez sur Importation…, puis sélectionnez le chemin d'accès au fichier de clé SSH privée correspondant à la clé publique que vous avez ajoutée à la VM.
Cliquez sur [ENTRÉE] Se connecter pour vous connecter à la VM.
In the Trusted Cloud console, activate Cloud Shell.
At the bottom of the Trusted Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
Client OpenSSH
Pour vous connecter à une VM à l'aide de SSH à partir d'un client OpenSSH, procédez comme suit :
Application PuTTY
Connectez-vous à une VM à l'aide de SSH à partir de l'application Windows PuTTY en procédant comme suit :
Application Chrome Secure Shell
Pour vous connecter à une VM à l'aide de SSH à partir de l'application Chrome Secure Shell, procédez comme suit :
Étape suivante
- Découvrez comment gérer l'accès aux VM.
- Découvrez comment transférer des fichiers vers des VM.
- Découvrez comment les connexions SSH aux VM Linux fonctionnent sur Compute Engine.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/19 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/08/19 (UTC)."],[[["\u003cp\u003eThis document guides users on connecting to Linux virtual machine (VM) instances with external IP addresses, detailing how to connect to VMs that do not have external IP's through the provided link.\u003c/p\u003e\n"],["\u003cp\u003eCompute Engine offers various methods to connect to Linux VMs, including using the Google Cloud console, gcloud CLI, OpenSSH client, PuTTY app, and Secure Shell Chrome app.\u003c/p\u003e\n"],["\u003cp\u003eBefore connecting, users should set up authentication and can install the Google Cloud CLI and set a default region and zone.\u003c/p\u003e\n"],["\u003cp\u003eSSH key management is essential for connecting to VMs, with options to create ephemeral or persistent keys, and users can add SSH keys to VMs as needed.\u003c/p\u003e\n"],["\u003cp\u003eSupported operating systems include all public Linux images on Compute Engine, although Fedora CoreOS images require setting up SSH access in advance, and troubleshooting information is provided for failed SSH connections.\u003c/p\u003e\n"]]],[],null,["Linux\n\n*** ** * ** ***\n\nThis document describes how to connect to Linux virtual machine (VM) instances\nthat have external IP addresses by using SSH keys. To learn how to connect to\nVMs that don't have external IP addresses, see\n[Connection options for internal-only VMs](/compute/docs/connect/ssh-internal-ip).\nTo learn how to connect to Linux VMs using SSH certificates, see\n[Require SSH certificates for OS Login VMs](/compute/docs/oslogin/certificates).\n\nFor information about\nhow SSH connections work in Compute Engine, including SSH key configuration\nand storage, see [SSH connections to Linux VMs](/compute/docs/instances/ssh).\n| **Note:** When a user connects to a VM, that user can use all of the IAM permissions granted to the service account attached to the VM.\n\nBefore you begin\n\n- If you haven't already, set up [authentication](/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:\n\n Select the tab for how you plan to use the samples on this page: \n\n Console\n\n\n When you use the Google Cloud console to access Google Cloud services and\n APIs, you don't need to set up authentication.\n\n gcloud\n 1.\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 | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\nSupported operating systems\n\nThese connection methods are supported for all\n[public Linux images](/compute/docs/images/os-details) that are available on\nCompute Engine. For Fedora CoreOS images, you must\n[set up SSH access](https://docs.fedoraproject.org/en-US/fedora-coreos/tutorial-containers/)\nbefore you can use these methods.\n\nConnect to VMs\n\nTo connect to a VM, complete the steps in one of the following tabs. \n\nConsole\n\nConnect to VMs using [SSH-in-browser](/compute/docs/ssh-in-browser) from the\nGoogle Cloud console, by doing the following:\n\n\n1. In the Google Cloud console, go to the **VM instances** page.\n\n [Go to VM instances](https://console.cloud.google.com/compute/instances)\n2. In the list of virtual machine instances, click **SSH** in the row of the instance that you want to connect to.\n\n\u003cbr /\u003e\n\n| **Note:** When you connect to VMs using the Google Cloud console, Compute Engine creates an ephemeral SSH key for you. For more information about SSH keys, see [SSH connections to Linux VMs](/compute/docs/instances/ssh).\n\ngcloud\n\nConnect to a VM using SSH by running the\n[`gcloud compute ssh` command](/sdk/gcloud/reference/compute/ssh):\n\n1. In the Google Cloud console, activate Cloud Shell.\n2. [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n3. At the bottom of the Google Cloud console, a [Cloud Shell](/shell/docs/how-cloud-shell-works) session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.\n4. Run the following command:\n\n ```\n gcloud compute ssh --project=PROJECT_ID --zone=ZONE VM_NAME\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of the project that contains the VM\n - \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the name of the zone that the VM is located in\n - \u003cvar translate=\"no\"\u003eVM_NAME\u003c/var\u003e: the name of the VM\n\n If you have [set default\n properties](/compute/docs/gcloud-compute#default-properties) for the Google Cloud CLI, you can omit the `--project` and\n `--zone` flags from this command. For example: \n\n ```\n gcloud compute ssh VM_NAME\n ```\n\n| **Note:** When you connect to VMs using the gcloud CLI, Compute Engine creates a persistent SSH key for you. For more information about SSH keys, see [SSH connections to Linux VMs](/compute/docs/instances/ssh).\n\nOpenSSH client\n\nConnect to a VM using SSH from an OpenSSH client, do the following:\n\n1. [Add an SSH key to the VM](/compute/docs/connect/add-ssh-keys) if you haven't already.\n2. In the Google Cloud console, go to the **VM Instances** page and find the\n\n external IP address\n\n of the\n\n VM that you want to connect to.\n\n [Go to VM Instances](https://console.cloud.google.com/compute/instances)\n3. Open a terminal on your workstation.\n4. Connect to the\n\n VM by running the following command:\n\n ```\n ssh -i PATH_TO_PRIVATE_KEY USERNAME@EXTERNAL_IP\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePATH_TO_PRIVATE_KEY\u003c/var\u003e: the path to the private SSH key file that corresponds to the public key you added to the VM.\n - \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: your username. If you manage your SSH keys in metadata, the username is what you specified when you [created the SSH key](/compute/docs/connect/create-ssh-keys). For OS Login accounts, the username is [defined in your Google profile](/compute/docs/connect/add-ssh-keys#os-login). For example, `cloudysanfrancisco_example_com` or `cloudysanfrancisco`.\n - \u003cvar translate=\"no\"\u003eEXTERNAL_IP\u003c/var\u003e: the external IP address of the VM.\n\nPuTTY app\n\nConnect to a VM using SSH from the Windows PuTTY app, by doing the following:\n\n1. [Add an SSH key](/compute/docs/connect/add-ssh-keys) to the VM if you haven't already.\n2. If your workstation doesn't already have the PuTTY app installed, [download the PuTTY package files](http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html).\n3. In the Google Cloud console, go to the **VM Instances** page and find the\n\n external IP address\n\n of the VM that you want to connect to.\n\n [Go to VM Instances](https://console.cloud.google.com/compute/instances)\n4. Open the PuTTY app. A connection configuration window opens.\n5. In the `Host Name` field, enter the username associated with the SSH key, and\n the\n\n external IP address\n\n of the VM that you want to connect to. Use the following format:\n\n ```\n USERNAME@EXTERNAL_IP\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: your username. If you manage your SSH keys in metadata, the username is what you specified when you [created the SSH key](/compute/docs/connect/create-ssh-keys). For OS Login accounts, the username is [defined in your Google profile](/compute/docs/connect/add-ssh-keys#os-login). For example, `cloudysanfrancisco_example_com` or `cloudysanfrancisco`.\n - \u003cvar translate=\"no\"\u003eEXTERNAL_IP\u003c/var\u003e: the external IP address of the VM.\n6. In the **Category** menu, navigate to **Connection \\\u003e\n SSH \\\u003e Auth**.\n7. In the **Private key file for authentication** field, select the private SSH key file that corresponds to the public key you added to the VM.\n8. Click **Open** to connect to the VM.\n\nSecure Shell Chrome app\n\nTo connect to a VM using SSH from the Secure Shell Chrome app, do the\nfollowing:\n\n1. [Add an SSH key to the VM](/compute/docs/connect/add-ssh-keys) if you\n haven't already.\n\n2. Install\n [Secure Shell](https://chrome.google.com/webstore/detail/secure-shell/iodihamcpbpeioajjeobimgagajmlibd)\n on your Chromebook or Chrome browser if you have not done so already.\n\n3. In the Google Cloud console, go to the **VM Instances** page and\n find the external IP address of the VM that you want to connect\n to.\n\n [Go to VM Instances](https://console.cloud.google.com/compute/instances)\n4. Open the Secure Shell in a Chrome browser tab address bar, by doing the\n following:\n\n - Type `ssh`.\n - Press `Space`.\n - Press `Enter`.\n5. Click **\\[New Connection\\]**.\n\n6. In the **username** field, enter your username. If you manage your SSH\n keys in metadata, the username is what you specified when you\n [created the SSH key](/compute/docs/connect/create-ssh-keys). For OS\n Login accounts, the username is\n [defined in your Google profile](/compute/docs/connect/add-ssh-keys#os-login).\n For example, `cloudysanfrancisco_example_com` or `cloudysanfrancisco`.\n\n7. In the **hostname** field, enter the external IP address of the VM.\n\n8. In the **Identity** field, click **Import...** and select the path to\n the private SSH key file that corresponds to the public key you added to\n the VM.\n\n9. Click **\\[ENTER\\] Connect** to connect to the VM.\n\nTroubleshooting\n\nTo find methods for diagnosing and resolving failed SSH connections, see\n[Troubleshooting SSH](/compute/docs/troubleshooting/troubleshooting-ssh).\n\n\nWhat's next\n\n- Learn how to [manage access to VMs](/compute/docs/instances/access-overview).\n- Learn how to [transfer files to VMs](/compute/docs/instances/transfer-files).\n- Learn how [SSH connections to Linux VMs](/compute/docs/instances/ssh) work on Compute Engine."]] -