Cannot Access SSH After Restoring a Snapshot in GCP

Hi, I have an issue with a virtual machine in Google Cloud. I have multiple servers in GCP, and I regularly create snapshots of their disks as backups. However, when I restore a snapshot to a new Linux VM instance, the restoration completes successfully, but I cannot connect via SSH.

Some additional details:

The firewall rule allowing SSH traffic (tcp:22) is correctly configured and assigned to the VM via network tags.
The instance has an external IP assigned and should be accessible.
I have tried connecting through the GCP console, but it does not work either.
I would appreciate any suggestions on what else I could check or if anyone has encountered a similar issue.

Tks

Hi @Coordinador_TIC ,

Welcome to Google Cloud Community!

Here are some basic troubleshooting steps you can follow:

  1. Check Serial Console Output for Boot or Network Issues:

If SSH isn’t working both externally and through the GCP console, the issue may be with the OS or networking.

Check the Serial Console logs and if you see errors related to cloud-init or missing SSH keys, it may be interfering with SSH access.

gcloud compute instances get-serial-port-output --zone

  1. Verify SSH Keys:

Verify that the instance’s SSH configuration is correct and ensure SSH keys are properly restored in the ~/.ssh/authorized_keys file. Check the file’s permissions (should be 600) and its contents through the serial console. You can also review SSH key settings in the GCP Console under Compute Engine > VM instances > [Instance name] > SSH keys.

  1. Verify the instance’s network configuration:

Ensure that the instance is properly configured to use the correct subnet and network by checking the settings in the GCP Console under VPC network > Subnets and VPC network > Networks.

  1. Check SSH Daemon Status:

Verify if the SSH daemon is running on the new instance and, if necessary, restart it using the appropriate command for your Linux distribution.

sudo service ssh restart

or

sudo systemctl restart sshd

  1. Check Disk Space:

The authorized_keys file on the restored disk may be corrupted, have incorrect permissions, or lack the necessary key if you didn’t rely solely on GCP metadata keys. Corrupt disk images from snapshots can also disrupt networking or SSH configurations, and if the boot disk is damaged, the instance might fail to boot properly.

Option 1: Check the Disk via Serial Console (Replace /dev/sda1 with your actual boot partition)

sudo fsck -y /dev/sda1

Option 2: Attach Disk to a Recovery VM: Detach the boot disk from the non-working instance, attach it to another VM, then mount and inspect the logs for issues.

sudo mkdir /mnt/recovery

sudo mount /dev/sdb1 /mnt/recovery

cat /mnt/recovery/var/log/syslog | grep ssh

If you need further assistance, you can reach out to Google Cloud Support at any time.

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.