Associate Cloud Engineer ยท Compute Engine: choosing, launching and scaling
OS Login
Using IAM to control SSH access (roles/compute.osLogin, osAdminLogin), enabling via metadata, 2-step verification, comparison with metadata-based SSH keys.
Key points
- OS Login controls SSH access with IAM.
- Turn it on with the metadata key enable-oslogin=TRUE on a project or a single VM.
- Grant roles/compute.osLogin for normal login or roles/compute.osAdminLogin for administrator (sudo) access.
- Add enable-oslogin-2fa=TRUE to require 2-step verification.
- Unlike metadata-based SSH keys, access is revoked centrally by removing the IAM role.
Source: https://docs.cloud.google.com/compute/docs/oslogin/set-up-oslogin
Practice questions
Which metadata setting enables OS Login?
- os-login=on
- enable-iam-ssh=TRUE
- enable-oslogin=TRUE
- oslogin-mode=enabled
Show answer
Answer: C. enable-oslogin=TRUE
The key is enable-oslogin with the value TRUE, set on the project or the instance. The other keys are not recognized.
Which are advantages of OS Login over metadata-based SSH keys?
- Access is granted and revoked through IAM
- It can require 2-step verification
- You must copy a public key into each VM's metadata
- It works only with Windows VMs
- It needs no IAM role for users
Show answer
Answer: A. Access is granted and revoked through IAM, B. It can require 2-step verification
OS Login centralizes access in IAM, so revoking a role removes access, and it can enforce 2-step verification. Per-VM key files are the old approach.
True or false: granting roles/compute.osLogin gives the user sudo rights on the VM.
Show answer
Answer: False
False. osLogin gives a standard login. Sudo requires roles/compute.osAdminLogin.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
