Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Linux
Dokumen ini menjelaskan cara terhubung ke instance virtual machine (VM) Linux
yang memiliki alamat IP eksternal menggunakan kunci SSH. Untuk mempelajari cara terhubung ke
VM yang tidak memiliki alamat IP eksternal, lihat
Opsi koneksi untuk VM khusus internal.
Untuk mempelajari cara menghubungkan ke VM Linux menggunakan sertifikat SSH, lihat Mewajibkan sertifikat SSH untuk VM Login OS.
Untuk mengetahui informasi tentang cara kerja koneksi SSH di Compute Engine, termasuk konfigurasi dan penyimpanan kunci SSH, lihat Koneksi SSH ke VM Linux.
Sebelum memulai
Jika Anda belum melakukannya, siapkan autentikasi.
Autentikasi adalah
proses yang digunakan untuk memverifikasi identitas Anda untuk mengakses Google Cloud layanan dan API.
Untuk menjalankan kode atau sampel dari lingkungan pengembangan lokal, Anda dapat melakukan autentikasi ke
Compute Engine dengan memilih salah satu opsi berikut:
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
Menginstal Google Cloud CLI.
Setelah penginstalan,
lakukan inisialisasi Google Cloud CLI dengan menjalankan perintah berikut:
Metode koneksi ini didukung untuk semua image Linux publik yang tersedia di Compute Engine. Untuk image Fedora CoreOS, Anda harus menyiapkan akses SSH sebelum dapat menggunakan metode ini.
Menghubungkan ke VM
Untuk terhubung ke VM, selesaikan langkah-langkah di salah satu tab berikut.
Konsol
Hubungkan ke VM menggunakan SSH-in-browser dari konsolGoogle Cloud , dengan melakukan hal berikut:
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.
Hubungkan ke VM dengan menjalankan perintah berikut:
ssh -i PATH_TO_PRIVATE_KEYUSERNAME@EXTERNAL_IP
Ganti kode berikut:
PATH_TO_PRIVATE_KEY: jalur ke file kunci SSH pribadi yang sesuai dengan kunci publik yang Anda tambahkan ke VM.
USERNAME:
nama
pengguna Anda. Jika Anda mengelola kunci SSH di
metadata, nama pengguna adalah nama yang Anda tetapkan saat
membuat kunci SSH.
Untuk
akun Login OS, nama pengguna
ditentukan di profil Google Anda.
Misalnya, cloudysanfrancisco_example_com atau cloudysanfrancisco.
EXTERNAL_IP: alamat IP eksternal VM.
Aplikasi PuTTY
Untuk terhubung ke VM menggunakan SSH dari aplikasi Windows PuTTY, lakukan hal berikut:
Buka aplikasi PuTTY. Jendela konfigurasi koneksi akan terbuka.
Di kolom Host Name, masukkan nama pengguna yang terkait dengan kunci SSH, dan alamat IP eksternal VM yang ingin Anda hubungkan. Gunakan format berikut:
USERNAME@EXTERNAL_IP
Ganti kode berikut:
USERNAME:
nama
pengguna Anda. Jika Anda mengelola kunci SSH di
metadata, nama pengguna adalah nama yang Anda tetapkan saat
membuat kunci SSH.
Untuk
akun Login OS, nama pengguna
ditentukan di profil Google Anda.
Misalnya, cloudysanfrancisco_example_com atau cloudysanfrancisco.
EXTERNAL_IP: alamat IP eksternal VM.
Pada menu Kategori, buka Koneksi >
SSH > Auth.
Di kolom File kunci pribadi untuk autentikasi, pilih file kunci SSH pribadi yang sesuai dengan kunci publik yang Anda tambahkan ke VM.
Klik Buka untuk terhubung ke VM.
Aplikasi Chrome Secure Shell
Untuk terhubung ke VM menggunakan SSH dari aplikasi Chrome Secure Shell, lakukan
langkah berikut:
Buka Secure Shell di kolom URL tab browser Chrome dengan melakukan langkah berikut:
Ketik ssh.
Tekan Space.
Tekan Enter.
Klik [New Connection].
Di kolom nama pengguna, masukkan nama pengguna Anda. Jika Anda mengelola kunci SSH di metadata, nama pengguna adalah nama yang Anda tentukan saat membuat kunci SSH. Untuk akun Login OS, nama pengguna ditentukan di profil Google Anda.
Contohnya, cloudysanfrancisco_example_com atau cloudysanfrancisco.
Di kolom nama host, masukkan alamat IP eksternal VM.
Pada kolom Identitas, klik Impor..., lalu pilih jalur ke file kunci SSH pribadi yang sesuai dengan kunci publik yang ditambahkan ke VM.
Klik [ENTER] Connect untuk terhubung ke VM.
Pemecahan masalah
Untuk menemukan metode mendiagnosis dan menyelesaikan koneksi SSH yang gagal, lihat Memecahkan Masalah SSH.
[[["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-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,["# Connect to Linux VMs\n\nLinux\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\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\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---------------------------\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--------------\n\nTo connect to a VM, complete the steps in one of the following tabs. \n\n### Console\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\n### gcloud\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\n### OpenSSH 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\n### PuTTY 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\n### Secure 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---------------\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\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."]]