Prepare and test your skills

Prepare and test your skills

Authentication and Identity Management for remote SSH to Compute Engine (opens in a new tab) virtual machines (VMs) decides who can log in and how that permission is verified. Compute Engine supports metadata-based SSH keys stored on the project or instance, and OS Login (opens in a new tab) which centralizes login with a Google identity and Identity and Access Management (IAM). Metadata keys are checked once at upload time, while OS Login checks IAM permissions on every login. This difference controls where keys live, how long they last, and how quickly access can be revoked.
Metadata-based SSH key management stores SSH public keys directly in Compute Engine project metadata or instance metadata. A key in instance metadata grants access to that single VM only, while a key in project metadata grants access to all VMs in the project. Both placements grant root privileges on the Linux VM by default. Access is evaluated only once when the key is uploaded, and the key stays valid until an administrator removes it or deletes the VM or project. Suspending or deleting the user in Cloud Identity or Google Workspace does not remove keys already stored in metadata, so stale keys remain a persistence risk without manual cleanup.
OS Login for centralized IAM-based login control links a Linux user account to a Google identity and authorizes each SSH login with IAM. Users keep public keys in their OS Login profile tied to their Google account instead of in VM or project metadata. When OS Login is enabled on a VM, the guest agent fetches keys from the OS Login service and ignores keys stored in metadata. Permission is checked on every login, so removing IAM access or suspending the user in Cloud Identity or Google Workspace revokes VM access automatically. Administrators grant roles/compute.osLogin for login without sudo and roles/compute.osAdminLogin for login with sudo, and these roles can apply at the instance, project, folder, or organization level.
OS Login centralizes identity in four practical ways:
If the VM has an attached service account, OS Login also requires iam.serviceAccounts.actAs permission on every connection, because SSH access allows requesting credentials from the VM metadata server as that service account.
Provisioning of POSIX identity and short-lived certificates by OS Login combines a Linux account record with a temporary SSH certificate. OS Login creates the POSIX profile when a user first connects from the Google Cloud console or gcloud CLI, or when a key is imported through gcloud CLI or the OS Login API. The default username uses the format USERNAME_DOMAIN_SUFFIX, for example cloudysanfrancisco_gmail_com, with an ext_ prefix for users from a different organization and an sa_ prefix for service accounts, truncated to 32 characters. Google never accesses the private key, and an administrator can set a custom username to replace the default format.
Certificate-based login moves data through an ordered sequence:
Comparison and enforcement of metadata keys versus OS Login shows the tradeoff between simple per-VM keys and centralized IAM checks. Metadata keys are simple for one VM but need manual cleanup, while OS Login removes per-VM key handling and verifies IAM on each login.
| Model | Where keys live | Access scope | When access is checked |
|---|---|---|---|
| Metadata-based keys | In project or instance metadata | One VM for instance metadata, all VMs in project for project metadata, with root privileges | Once at key upload; valid until key removal or VM or project deletion |
| OS Login | In user OS Login profile; VM fetches keys from OS Login service | Controlled by IAM roles on instance, project, folder, or organization, with or without sudo | On every login; revoked when IAM is removed or user is suspended or deleted |
OS Login is controlled by the enable-oslogin metadata key, where TRUE enables it and FALSE disables it. By default OS Login is disabled, so VMs accept metadata-based keys. When OS Login is enabled, Compute Engine deletes the VM authorized_keys files and no longer accepts SSH keys stored in project or instance metadata. Instance-level metadata takes higher precedence than project-level metadata, so project-level TRUE does not stop someone with instance admin access from setting FALSE on one VM. To enforce consistent use, apply an organization policy for OS Login so attempts to set enable-oslogin to FALSE are rejected.
Exam tip: Instance-level enable-oslogin=FALSE disables OS Login even when project metadata sets it to TRUE; OS Login-enabled VMs ignore metadata-based SSH keys.
Methods of establishing remote connections to Compute Engine instances depend on the operating system and network path. Linux instances typically use Secure Shell (SSH) from a browser or command line, while Windows instances use a graphical desktop through Remote Desktop Protocol (RDP) (opens in a new tab). The Google Cloud console acts as the central starting point by showing instance addresses, creating Windows credentials, and launching direct access without manual key setup.
Role of the Google Cloud console in secure direct access is to provide discovery, credential creation, and connection launch for Compute Engine instances. The console VM instances page lists each Windows instance with its external IP address for internet access and its internal IP address for private network access. From the VM instance details page, an administrator can click Set Windows password under Remote access to create a Windows username and password. For RDP, the console provides an RDP button with a Download the RDP file option, so a preferred RDP client can open a ready-made connection file. The command gcloud compute instances list returns the same external and internal addresses for terminal or scripted workflows, but both console and gcloud CLI paths still depend on firewall rules and network connectivity.
Remote Desktop Protocol access for Windows instances opens the full graphical desktop of a Windows Compute Engine instance. Traffic flows from the RDP client on the local computer to the instance over TCP on port 3389, unless a different port is configured. The instance depends on a Virtual Private Cloud (VPC) firewall rule that allows TCP ingress to port 3389 and on a valid Windows username and password created on that instance. Choosing the correct address depends on the network boundary, where the external IP is used over the internet and the internal IP is used when the local network connects to the VPC through Cloud VPN or Cloud Interconnect.
To connect with the Microsoft Remote Desktop Connection app on Windows:
gcloud compute instances list.%systemroot%\system32\mstsc.exe.:port if a non-default port is used.IAP Desktop for private RDP is a Windows application for managing multiple Remote Desktop connections to Windows Compute Engine instances. Traffic flows from IAP Desktop on the local computer through Identity-Aware Proxy (IAP) TCP forwarding to the instance private address, so the instance does not require a public IP address. The VPC must be configured to allow IAP traffic to the instance, which replaces opening port 3389 to the internet. IAP Desktop depends on two prerequisites: the VPC firewall must allow IAP traffic to reach the instance, and IAP Desktop must be downloaded and installed locally. IAP Desktop is an open-source project and is not an officially supported Google product.
To connect with IAP Desktop:
Chrome Remote Desktop (opens in a new tab) for browser-based Windows access lets a user reach a computer through a web browser. The session flows from the Chrome Remote Desktop website to the Chrome Remote Desktop host service running on the instance, and it works for Windows, macOS, and Linux clients. The instance does not require a public IP address because the connection is brokered through the Google Account rather than direct internet RDP. Before browser access works, a Windows account and password must exist on the instance and the Chrome Remote Desktop service must be installed there. On Windows VMs a display device must also be enabled because the service needs a desktop to share.
To connect with Chrome Remote Desktop:
Comparison of Windows remote connection methods shows how client type, public IP need, and network path differ across options. Each method still requires Windows credentials on the instance, but the path from client to instance changes.
| Method | Public IP required | Network path | Authentication |
|---|---|---|---|
| IAP Desktop | No, uses IAP TCP forwarding | Traffic flows from local app through IAP to instance private address | Google Cloud project access plus Windows username and password |
| Microsoft Remote Desktop Connection app | Yes for internet, no for VPN or Interconnect | Traffic flows directly from client to external IP over internet, or to internal IP over Cloud VPN or Cloud Interconnect on TCP port 3389 | Windows username and password |
| Chrome Remote Desktop | No | Traffic flows from browser through Chrome Remote Desktop service linked to Google Account | Google Account sign-in, host PIN, plus Windows username and password |
| Other RDP clients | Yes for internet, no for VPN or Interconnect | Traffic flows directly from Android, iOS, or Mac client to external or internal IP on TCP port 3389 | Windows username and password |
Choose IAP Desktop when managing many private Windows instances without public IPs and IAP access is allowed. Choose the Microsoft app or another RDP client when direct RDP over the internet or over an existing VPN or Interconnect path is available and port 3389 is open. Choose Chrome Remote Desktop when browser access is preferred and installing the host service with a Google Account plus PIN is acceptable.
Exam tip: Use the external IP for RDP over the internet and the internal IP for RDP over Cloud VPN or Cloud Interconnect; the default RDP port is TCP 3389.
Security Protocols and Firewall Management for Compute Engine covers how Virtual Private Cloud (VPC) firewall rules and Identity-Aware Proxy (IAP) work together for secure remote administration. Firewall rules control which traffic can reach port 22 for SSH and port 3389 for RDP, while IAP for TCP forwarding adds identity-based authentication and authorization in front of those ports. Together they make it possible to administer instances that have no external IP address.
VPC firewall rules for SSH and RDP access are ingress rules that allow TCP traffic from a trusted source range to a specific port on target VMs. Port 22 carries SSH traffic for Linux administration, and port 3389 carries RDP traffic for Windows administration. The rule applies at the VPC network boundary, so traffic flows from the source range to the VM only when direction, target, protocol, and port all match. A secure approach for controlling SSH network access (opens in a new tab) allows ingress only from the IAP source range 35.235.240.0/20 to the required ports. The default rules default-allow-ssh and default-allow-rdp allow connections from all IP addresses, so they expose SSH and RDP directly to the public internet.
| Remote protocol | Destination port | Secure source range |
|---|---|---|
| SSH for Linux | TCP 22 | 35.235.240.0/20 |
| RDP for Windows | TCP 3389 | 35.235.240.0/20 |
Hierarchical firewall policies can enforce the same intent across multiple projects by applying rules to folders in the resource hierarchy. A typical policy first allows ingress from 35.235.240.0/20 to port 22, then denies ingress from 0.0.0.0/0 to port 22, so only IAP-forwarded SSH reaches the VMs. For VMs that need no external access, deploy the VM without an external IP address or configure firewall rules so ingress from outside the VPC is not allowed.
Exam tip: Allow TCP to ports 22 and 3389 only from 35.235.240.0/20 for IAP access; the default rules allow the same ports from all addresses and must be removed to block direct internet access.
IAP TCP forwarding without external IP addresses tunnels SSH and RDP connections through Google identity checks to the internal address of a VM. Traffic flows from the client device to the IAP proxy, and then from the IAP proxy to the primary internal IPv4 address of nic0 on the target VM. Because the VM is reached by its internal address, the VM does not need an external IP address and does not need to be directly reachable from the internet. The SSH session itself stays end-to-end encrypted between client and VM, so IAP cannot inspect session contents and does not provide session recording.
IAP protects the connection with four checks and controls before the session reaches the VM:
IAP audit logs contain connection metadata but reveal nothing about activity inside the session. If session recording is required, use a bastion VM that terminates the SSH connection and records it, allow SSH to target VMs only from that bastion VM, and allow access to the bastion VM only through IAP TCP forwarding.
enable-oslogin=FALSE overrides project-level enable-oslogin=TRUE, and OS Login-enabled VMs ignore SSH keys stored in project or instance metadata.Metadata-based SSH keys are stored in project or instance metadata and checked only once at upload time, while OS Login stores keys in the user OS Login profile and checks Identity and Access Management (IAM) permissions on every login. Instance metadata grants access to that single virtual machine only and project metadata grants access to all virtual machines in the project, both with root privileges by default, while OS Login scope is controlled by IAM roles with or without sudo. Suspending or deleting a user revokes OS Login access automatically but does not remove keys already stored in metadata.
Use the external IP address for Remote Desktop Protocol access over the internet and the internal IP address for access over Cloud VPN or Cloud Interconnect. Traffic flows directly from the client to the instance on TCP port 3389 unless a different port is configured. The connection requires a Virtual Private Cloud (VPC) firewall rule allowing TCP ingress to port 3389 and a valid Windows username and password created on that instance.
Identity-Aware Proxy TCP forwarding tunnels connections from the client device to the Identity-Aware Proxy proxy and then to the primary internal IPv4 address of nic0 on the target virtual machine, so the virtual machine does not need an external IP address or direct internet reachability. The Secure Shell session stays end-to-end encrypted between client and virtual machine, while Identity-Aware Proxy verifies Google credential authentication, Identity and Access Management authorization such as the IAP-secured Tunnel User role, optional context-aware access, and auditing of connection attempts. Secure access requires Virtual Private Cloud firewall rules allowing ingress only from 35.235.240.0/20 to TCP port 22 for Secure Shell and TCP port 3389 for Remote Desktop Protocol.
By default OS Login is disabled so virtual machines accept metadata-based keys, and setting the enable-oslogin metadata key to TRUE enables OS Login while FALSE disables it. When OS Login is enabled, Compute Engine deletes the virtual machine authorized_keys files and no longer accepts SSH keys stored in project or instance metadata. Instance-level metadata takes higher precedence than project-level metadata, so instance-level FALSE disables OS Login even when project metadata sets TRUE, and consistent enforcement requires an organization policy that rejects attempts to set enable-oslogin to FALSE.
Your organization is deploying several Windows virtual machine (VM) instances in a Virtual Private Cloud (VPC) network on Compute Engine.
To meet corporate security policies, you must fulfill the following requirements:
What should you do to allow secure administrative access?
Last updated