If you have Linux virtual machine (VM) instances running on Google Cloud, you might need to share or restrict user or application access to your VMs.
If you need to manage user access to your Linux VM instances, you can use one of the following methods:
If you need to manage application access to your VM instances, see Use SSH with service accounts.
Managing user access
OS Login
In most scenarios, we recommend using OS Login. The OS Login feature lets you use Compute Engine IAM roles to manage SSH access to Linux instances. You can add an extra layer of security by setting up OS Login with two-factor authentication, and manage access at the organization level by setting up organization policies.
To learn how to enable OS Login, see Set up OS Login.
Manage SSH keys in metadata
If you are running your own directory service for managing access, or are otherwise unable to set up OS Login, you can manually manage SSH keys in metadata.
Risks of manual key management
Some of the risks of manual SSH key management include the following:
- All users who connect to VMs using SSH keys stored in metadata have
sudo
access to VMs. - You must keep track of expired keys and delete keys for users who shouldn't have access to your VMs. For example, if a team member leaves your project, you must manually remove their keys from metadata, so they can't continue to access your VMs.
- Specifying your gcloud CLI or API calls incorrectly can potentially wipe out all of the public SSH keys in your project or on your VMs, which disrupts connections for your project members.
- Users and service accounts that have the ability to modify project metadata can add SSH keys for all VMs in the project except for VMs that block project-level SSH keys.
If you aren't sure that you want to manage your own keys, use Compute Engine tools to connect to your instances instead.
What's next?
- Learn how to set up OS Login.
- Learn how to create SSH keys.
- Learn how to add SSH keys to VMs.
- Learn how to restrict SSH keys from VMs.