0

I accidentally removed my user profile with SSH key on google cloud VM, so now I don't even have the possibility to connect to that machine. It's not a big deal since that VM is for testing purposes, but it would be nice to know what to do if a similar situation would have a place in the future.

  • For the sake of understanding the context, did you delete the user home folder? userdel'ed the user? – jabbson Jan 17 '21 at 19:25

2 Answers2

0

Have you try to go to https://console.cloud.google.com/security/kms and retrieve the public key ?

0

There are multiple options you can choose to access your Instance if you mistakenly delete the SSH key:

OS Login: It will allow you to use Compute Engine IAM roles to manage SSH access to Linux instances. Besides you could add an extra layer of security configuring it with two-factor authentication, managing access at the Organization Level, setting up Organization Policies

Manage SSH keys in metadata: Access to Linux instances by manually creating SSH keys and editing public SSH key metadata.

Alternatively to SSH you could use Serial Console to access your Instance.

  • First of all, you will need to enable Serial Console Access in that Instance.
  • If you know the password of the root user account for this VM instance, then try to access via Serial Console using the root account.
  • If you don’t know remember the password or never setup it, follow this procedure:
    • Go to the VM instances page and click on the instance name of your VM
    • Click the Edit button at the top of the page
    • Under Custom metadata, click Add item
    • Set "key" to startup-script and set "Value" with the following script:

#! /bin/bash echo "root:<---YOUR-PASSWORD--->" | chpasswd

NOTE: Change the value "<---YOUR-PASSWORD--->"" for a password of your choice. For security reasons, I would recommend you to remove the startup script and change the password from within the instance once you regain access to the instance, otherwise anyone with view access to this VMs can see the password.

  • Reboot your Instance, this way the startup-script will be executed.
  • Now you should be able to access Using Serial Console

Regards

agmance
  • 36
  • 3