Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Linux
Neste documento, descrevemos como se conectar a instâncias de máquina virtual (VM) do Linux
que têm endereços IP externo usando chaves SSH. Para saber como se conectar a
VMs que não têm endereços IP externo, consulte
Opções de conexão para VMs somente internas.
Para saber como se conectar a VMs do Linux usando certificados SSH, consulte
Exigir certificados SSH para VMs de Login do SO.
Para mais informações sobre como as conexões SSH funcionam
no Compute Engine, incluindo a configuração e o armazenamento de chaves SSH, consulte
Conexões SSH com VMs do Linux.
Antes de começar
Configure a autenticação, caso ainda não tenha feito isso.
A autenticação é
o processo de verificação da sua identidade para acesso a serviços e APIs do Google Cloud .
Para executar códigos ou amostras de um ambiente de desenvolvimento local, autentique-se no
Compute Engine selecionando uma das seguintes opções:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and
APIs, you don't need to set up authentication.
gcloud
Instale a CLI do Google Cloud.
Após a instalação,
inicialize a Google Cloud CLI executando o seguinte comando:
Esses métodos de conexão são compatíveis com todas as
imagens públicas do Linux disponíveis no
Compute Engine. Para imagens do Fedora CoreOS, é necessário
configurar o acesso SSH
antes de usar esses métodos.
Conectar-se às VMs
Para se conectar a uma VM, conclua as etapas em uma das guias a seguir.
Console
Para se conectar a VMs usando o SSH no navegador no
consoleGoogle Cloud , faça o seguinte:
In the Google Cloud console, go to the
VM instances page.
At the bottom of the Google 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.
PATH_TO_PRIVATE_KEY: o caminho para o arquivo de
chave SSH privada que corresponde à chave pública adicionada à VM.
USERNAME:
seu
nome de usuário. Se você gerencia suas chaves SSH em
metadados, o nome de usuário será aquele que você especificou
quando criou a chave SSH.
Para
contas do Login do SO, o nome de usuário é
definido no seu perfil do Google.
Por exemplo, cloudysanfrancisco_example_com ou cloudysanfrancisco.
EXTERNAL_IP: o endereço IP externo da
VM.
App PuTTY
Para se conectar a uma VM usando SSH do app PuTTY Windows, faça o seguinte:
Abra o app PuTTY. Uma janela de configuração de conexão será aberta.
No campo Host Name, digite o nome de usuário associado à chave SSH e
o
endereço IP externo
da VM a que você quer se conectar. Use o seguinte formato:
USERNAME@EXTERNAL_IP
Substitua:
USERNAME:
seu
nome de usuário. Se você gerencia suas chaves SSH em
metadados, o nome de usuário será aquele que você especificou quando
criou a chave SSH.
Para
contas do Login do SO, o nome de usuário é
definido no seu perfil do Google.
Por exemplo, cloudysanfrancisco_example_com ou cloudysanfrancisco.
EXTERNAL_IP: o endereço IP externo da
VM.
No menu Category, navegue até
Connection > SSH > Auth.
No campo Arquivo de chave privada para autenticação, selecione o arquivo da chave SSH privada que corresponde à chave pública adicionada à VM.
Clique em Abrir para se conectar à VM.
App Secure Shell do Chrome
Para se conectar a uma VM usando SSH no app Secure Shell do Chrome, faça o
seguinte:
Abra o Secure Shell em uma barra de endereço da guia do navegador Chrome fazendo o
seguinte:
Digite ssh.
Pressione Space.
Pressione Enter.
Clique em [Nova conexão].
No campo nome de usuário, digite seu nome de usuário. Se você gerencia suas chaves SSH
em metadados, o nome de usuário será aquele que você especificou quando
criou a chave SSH. Para contas do Login do SO,
o nome de usuário é
definido no seu perfil do Google.
Por exemplo, cloudysanfrancisco_example_com ou cloudysanfrancisco.
No campo nome do host, digite o endereço IP externo da VM.
No campo Identidade, clique em Importar... e selecione o caminho para
o arquivo de chave SSH privada que corresponde à chave pública adicionada
à VM.
Clique em [ENTER] Conectar para se conectar à VM.
Solução de problemas
Para encontrar métodos de diagnóstico e resolução de conexões SSH com falha, consulte
Solução de problemas de SSH.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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."]]