Configuring OS Login

5 minutes 5 Questions

OS Login is a Google Cloud feature that simplifies SSH access management to Compute Engine instances by using IAM permissions instead of managing individual SSH keys. Here's how to configure it effectively. **Enabling OS Login at Project Level:** Set the metadata key 'enable-oslogin' to 'TRUE' at the project level using Cloud Console or gcloud command: gcloud compute project-info add-metadata --metadata enable-oslogin=TRUE **Enabling OS Login at Instance Level:** For specific instances, add the same metadata during creation or update: gcloud compute instances add-metadata INSTANCE_NAME --metadata enable-oslogin=TRUE **Granting IAM Roles:** Users need appropriate IAM roles to connect: - roles/compute.osLogin: Provides standard user access - roles/compute.osAdminLogin: Provides administrator access with sudo privileges - roles/iam.serviceAccountUser: Required when connecting to instances running as service accounts **Two-Factor Authentication:** For enhanced security, enable OS Login 2FA by setting 'enable-oslogin-2fa' to 'TRUE' in metadata. Users must have 2FA configured on their Google accounts. **Connecting to Instances:** Once configured, users can connect using: gcloud compute ssh INSTANCE_NAME The system automatically creates a user account based on the user's Google identity. **Organization Policies:** Administrators can enforce OS Login across the organization using the constraint 'compute.requireOsLogin' to ensure consistent access management. **Benefits:** - Centralized access management through IAM - Automatic SSH key lifecycle management - Integration with Cloud Identity and Google Workspace - Audit logging for all access attempts - No need to distribute or rotate SSH keys manually **Considerations:** - Windows instances are not supported - Some legacy applications may require traditional SSH key management - Users must have Google accounts linked to the project OS Login provides enterprise-grade access control while reducing operational overhead for managing Linux instance access in Google Cloud environments.

Configuring OS Login for GCP Associate Cloud Engineer

Why is OS Login Important?

OS Login is a critical security feature in Google Cloud Platform that simplifies and centralizes SSH access management to your Compute Engine virtual machines. Instead of managing individual SSH keys across multiple VMs, OS Login integrates with Cloud Identity and IAM, providing a unified and secure approach to access control. This reduces administrative overhead and enhances security posture by leveraging Google's identity management infrastructure.

What is OS Login?

OS Login is a feature that uses IAM roles to manage SSH access to Linux instances and manages user accounts on Compute Engine instances. When enabled, it links Linux user accounts to Google identities, allowing you to manage access through IAM policies rather than managing SSH keys manually.

Key components include:
- Cloud Identity integration: Users authenticate using their Google identity
- IAM role-based access: Access is controlled through IAM roles
- POSIX account management: Automatic creation and management of Linux user accounts
- Two-factor authentication support: Optional 2FA for enhanced security

How OS Login Works

1. Enabling OS Login: Set the metadata key enable-oslogin to TRUE at the project or instance level

2. Required IAM Roles:
- roles/compute.osLogin - Grants standard user access (no sudo)
- roles/compute.osAdminLogin - Grants administrative access with sudo privileges
- roles/iam.serviceAccountUser - Required when connecting to instances running as service accounts

3. Authentication Flow:
- User initiates SSH connection
- Google verifies the user's identity and IAM permissions
- If authorized, a POSIX account is created or updated on the VM
- SSH session is established

4. Enabling 2FA: Set enable-oslogin-2fa to TRUE for additional security

Configuration Methods

Using gcloud CLI:
gcloud compute project-info add-metadata --metadata enable-oslogin=TRUE

For a specific instance:
gcloud compute instances add-metadata INSTANCE_NAME --metadata enable-oslogin=TRUE

Granting access:
gcloud projects add-iam-policy-binding PROJECT_ID --member=user:EMAIL --role=roles/compute.osLogin

Exam Tips: Answering Questions on Configuring OS Login

1. Recognize the scenario: Questions about centralized SSH management, reducing key management overhead, or integrating with corporate identity systems typically point to OS Login as the answer.

2. Know the roles: Memorize that compute.osLogin provides standard access while compute.osAdminLogin provides sudo privileges. This distinction appears frequently in exams.

3. Understand metadata keys: Remember that enable-oslogin=TRUE is set as metadata, not as a separate configuration setting.

4. Service account awareness: When a question mentions connecting to VMs running as service accounts, remember that iam.serviceAccountUser role is also needed.

5. Project vs Instance level: OS Login can be enabled at both levels. Project-level applies to all new instances, while instance-level can override project settings.

6. 2FA questions: When questions ask about adding an extra layer of security to SSH access, consider OS Login with 2FA enabled.

7. Migration scenarios: If a question describes moving from manual SSH key management to a more secure, centralized approach, OS Login is likely the correct answer.

8. Troubleshooting hints: If users cannot connect after OS Login is enabled, check that appropriate IAM roles are assigned and that the metadata is properly configured.

Common Exam Pitfalls to Avoid

- Do not confuse OS Login with project-wide SSH keys - they are different features
- Remember that OS Login requires proper IAM role assignments, not just enabling the feature
- OS Login works with Linux instances; Windows instances use different authentication mechanisms
Test mode:
More Configuring OS Login questions
29 questions (total)

Other Planning and Implementing a Cloud Solution concepts

AlloyDBAvailability policy for Compute EngineBigQueryBigtableChoosing and deploying data productsChoosing and deploying load balancersChoosing and deploying storage productsChoosing storage for Compute EngineCloud InterconnectCloud Next Generation Firewall (Cloud NGFW)Cloud RunCloud Run functionsCloud SQLCloud StorageCloud Storage classes (Standard, Nearline, Coldline, Archive)Cloud Storage object change notificationsCloud VPNCommand-line data uploadCompute EngineConfig ConnectorConfiguring VM ManagerCreating autoscaled managed instance groupsCreating a VPC with subnetsCustom machine typesCustom mode VPCDataflowDeploying containerized applications to GKEDeploying GKE clustersDeploying to serverless compute platformsEstablishing network connectivityEventarcFabric FASTFilestoreFirestoreFirewall ingress and egress rulesGKE AutopilotGoogle Cloud HyperdiskGoogle Cloud Managed Service for Apache KafkaGoogle Cloud NetApp VolumesGoogle Kubernetes Engine (GKE)Helm for KubernetesIaC versioning and state managementInfrastructure as code toolingInstalling kubectl CLIInstance templatesKnative servingLaunching a compute instanceLoading data into Google CloudMaintaining multi-region redundancyMemorystoreNetwork Service TiersPlanning and executing IaC deploymentsPrivate GKE clustersProcessing Pub/Sub eventsPub/SubRegional GKE clustersRegional Persistent DiskSecure TagsSelecting compute choices for workloadsService accounts in firewall rulesShared VPCSpannerSpot VM instancesSSH keys for Compute EngineStorage Transfer ServiceTerraform on Google CloudUsing Tags in Cloud NGFW policy rulesVPC Network PeeringZonal Persistent Disk