Hello Cloud Community,
I'm hitting a wall trying to get SSH public key authentication working consistently from Google Cloud Build to a Windows Server VM. The connection always fails with "Permission denied" (reported as "Failed password" in the VM's OpenSSH logs), and I've exhausted standard troubleshooting steps. I'm hoping someone here might have encountered a similar very specific issue or have insights.
My Setup:
The Core Problem: The SSH connection fails because the OpenSSH server (sshd) on the Windows VM consistently falls back to password authentication, indicating it's not correctly using the provided public key.
Troubleshooting Steps & Findings (Detailed):
SSH Key Propagation (Cloud Build & GCE Agent):
Windows VM OpenSSH Server (sshd) Configuration:
authorized_keys File & Directory Permissions (icacls):
Hostname Mismatch (Addressed in cloudbuild.yaml):
Google Compute Engine Agent (GCE Agent) Issues - The Biggest Mystery:
GCEGuestAgent: Error watching metadata: context canceled
GCEGuestAgent: Cannot connect to cloud logging, skipping flush: rpc error: code = PermissionDenied desc = Request had insufficient authentication scopes.
error details: name = ErrorInfo reason = ACCESS_TOKEN_SCOPE_INSUFFICIENT domain = googleapis.com metadata = map[method:google.logging.v2.LoggingServiceV2.WriteLogEntries service:logging.googleapis.com]
Manual SSH Test (Confirms Basic Connectivity, Not Key Auth):
My Questions to the Community:
Any insights or suggestions would be greatly appreciated! Thank you in advance for any help.
Hi @cbcbcb,
Welcome to Google Cloud Community!
The VM's access scopes can only be changed while the VM is STOPPED.
This cli command tells the VM instance to allow the attached service account to use all of its granted permissions.
gcloud compute instances set-service-account YOUR_VM_NAME \
--zone=YOUR_ZONE \
--scopes=cloud-platform
Via the Cloud Console:
Stop the VM.
Click "Edit".
Scroll to "Access scopes" and select "Allow full access to all Cloud APIs".
Save and Start the VM.
To answers your questions:
1. Has anyone encountered the "GCEGuestAgent: Request had insufficient authentication scopes" error when their VM's service account is already set to "Allow full access to all Cloud APIs"? What was the resolution?
Yes, this is common. The cause is almost always that the scope change was made after the VM was created, and the VM was never stopped and started from the GCP console. A simple OS-level reboot does not apply the new scopes. The resolution is the STOP/START cycle described above.
After fixing the VM's access scopes, you need to trigger the GCE Agent to re-sync the keys from GCP and then verify that it has successfully updated the local authorized_keys file.
2. Given that authorized_keys permissions are seemingly correct and a manually placed key still results in a password prompt, are there any less common sshd_config settings on Windows or user profile issues that could be causing sshd to ignore authorized_keys for public key authentication?
Here are the less common settings and profile issues that could be causing this behavior:
sshd_config are more specific than the basics and can override them.
If authorized_keys file must be UTF-8 (without BOM). Windows Notepad can save it as UTF-16 or add a hidden "Byte Order Mark" (BOM) at the beginning of the file, which makes it unreadable to sshd.
If the user account is locked out due to previous failed password attempts.
3. Are there any known issues with the GCE Agent or OpenSSH that might explain this behavior?
Known issue to GCE Agent scope:
On the error filter logs you’ve shared the “ACCESS_TOKEN_SCOPE_INSUFFICIENT” means the GCE Agent running on the VM will continue to operate with the old, more restrictive scopes until the instance is fully stopped and restarted.
Know issue to OpenSSH:
Your manual ssh key test with locally placed keys also will fail and can't continue to access your VMs.
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.