Recover instance access after losing the private key

If you have lost the private key used to connect to your cloud instance, you will not be able to log in using SSH.

You may still be able to recover access if password login is configured on the instance.


  • Confirm console login is enabled

    Before creating a new key pair, confirm whether you can log in to the instance console.

    Console login is only possible if password login was previously configured on the instance.

    This may be the case if:

    • You set a password during instance creation using a cloud-init configuration script.
    • You configured a password for a user account after creating the instance.

    To check:

    1. Navigate to Compute > Instances.
    2. Click the instance name.
    3. Open the Console tab.
    4. Try to log in using the username and password configured on the instance.

    If you can log in, continue with the steps below to create a new key pair and add the new public key to the instance.





  • If console login is not possible

    If the instance only allows SSH key authentication and no password login is configured, access cannot be recovered.

    In this case, you may need to:

    • Create a new instance
    • Restore data from backup, if available
    • Rebuild the environment manually

    This is why it is important to store private keys securely and keep backups of important data.





  • Create a new key pair

    Create a new SSH key pair that you will use to access the instance.

    The private key remains on your computer. The public key must be added to the instance.

    You can create a key pair in one of the following ways:

    a) Generate a key pair in your terminal, then import the public key.

    b) Create a key pair in the Cloud dashboard and download the private key file.

    Creating a new key pair in the Cloud dashboard does not automatically update an existing instance. To use the new key, you must add the new public key to the instance’s authorized_keys file.





  • Add the new public key to the instance

    After creating a new key pair, add the new public key to the instance through the console.

    Step 1: Log in to the instance console

    1. 1
      Navigate to Compute > Instances.
    2. 2
      Click the instance name.
    3. 3
      Open the Console tab.
    4. 4
      Log in using the username and password configured on the instance.

    Step 2: Open the SSH directory

    Run the following commands:
    mkdir -p ~/.ssh
    cd ~/.ssh

      Step 3: Edit the authorized_keys file

      Run:
        nano authorized_keys
        Paste your new public key into the file.
        Example public key format:
            ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...
            Save the file and exit the editor.

            Step 4: Set the correct permissions

            Run:

                chmod 700 ~/.ssh
                    chmod 600 ~/.ssh/authorized_keys

                    Step 5: Connect using the new key

                    You can now connect to your instance using your new private key.

                    Follow the steps to connect to cloud instances via SSH.





                  • Change the SSH key for an existing instance

                    To change the SSH key used to access an existing instance, you need to add the new public key to the instance.

                    Creating, deleting or renaming a key pair in the Cloud dashboard does not automatically change the keys already stored inside an existing instance.

                    If you still have access to the instance, add the new public key to the authorized_keys file for the user you use to connect.

                    If you no longer have SSH access, you can only do this through the instance console if password login is already configured.





                  • Security reminder

                    Do not share your private key or server password with support.

                    Your private key gives access to your instance and should be stored securely, such as in an encrypted password manager or secure key store.



                  What happens next

                  Once you have added the new public key to the instance, use the matching private key to connect via SSH.

                  To avoid losing access in the future, keep secure backups of important private keys and create separate user accounts or SSH keys for administrators who need access.