Stay organized with collections
Save and categorize content based on your preferences.
This document describes how to use a
service account to connect to
Compute Engine virtual machine (VM) instances using SSH. Setting up SSH for a
service account enables you to
configure apps to use SSH, which
can help you to automate your workloads.
If you haven't already, then set up authentication.
Authentication is
the process by which your identity is verified 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:
After installing the Google Cloud CLI,
initialize it by running the following command:
If you use OS Login, you require all the permissions included one of
the OS Login IAM roles
on the service account.
If you don't use OS Login, the service account also requires the
compute.projects.setCommonInstanceMetadata permission.
Use the gcloud CLI
--impersonate-service-account flag
to connect directly to a VM using a service account's identity. Run the
following command to connect to a VM as a service account:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-13 UTC."],[[["This document explains how to use a service account to connect to Compute Engine virtual machine (VM) instances using SSH, which helps automate workloads."],["Connecting to VMs as a service account can be done by directly impersonating the service account using the `gcloud` CLI with the `--impersonate-service-account` flag, requiring specific permissions such as the Service Account Token Creator role."],["You can also impersonate a service account from within a VM, requiring the Service Account User role and the `compute.projects.setCommonInstanceMetadata` permission, if OS login is not used."],["Before connecting to VMs, you must authenticate and may need to set up a default region and zone."],["Specific service accounts require different permissions depending on the context, these including but not limited to the OS Login IAM roles, Service Account Token Creator role and Service Account User role."]]],[]]