Skip to main content
Recovery mode opens a root shell on a Linux Virtual Machine or Bare Metal server from the console when the private key is lost and no console password is set. Install a public key when SSH must accept a new key.
1

Open the server

Log in to the Gcore Customer Portal and navigate to Cloud > Virtual Instances. Open the Virtual Machine.
Virtual Instance page with Access to Console and the ubuntu login
The login beside Access to Console is the account SSH accepts. On the Ubuntu image that account is ubuntu.
2

Open the console

Bare Metal server page with Access to Console beside the IP address
Click Access to Console to open the console in a browser tab, with Send CtrlAltDel at the top right.
Not every Bare Metal platform provides Access to Console.
VNC console with Send CtrlAltDel and the Ubuntu login
3

Open the GRUB menu

Open the boot menu before the login prompt:
  1. Click the console screen so keystrokes reach the server.
  2. Click Send CtrlAltDel.
  3. Press Escape until GNU GRUB appears.
The GRUB menu stays hidden, and Escape registers only during Booting from Hard Disk.... If the Ubuntu login prompt appears, Escape missed the menu, so click the console screen and repeat this step.
GNU GRUB menu with Ubuntu and Advanced options for Ubuntu
4

Boot recovery mode

On an Ubuntu cloud image, select Advanced options for Ubuntu and press Enter. Then select the entry that ends with (recovery mode) and press Enter.
GRUB advanced options with the recovery mode entry highlighted
5

Open a root shell

In Recovery Menu (filesystem state: read-only), select root (Drop to root shell prompt) and press Enter.
Recovery menu with Drop to root shell prompt highlighted
At Press Enter for system maintenance (or press Control-D to continue):, press Enter. The menu frame can remain on screen after the shell starts, while the shell is active once a prompt ending in ~# appears at the bottom.

Install a public key

Use this section when the server must accept a new SSH key. The root shell from the procedure above is already open.
1

Remount the root filesystem

Recovery mounts the root filesystem read-only, so remount it before writing the key:
When the command returns to the prompt without an error, the root filesystem accepts writes.
Root shell after remounting the filesystem read-write
2

Install the public key

Write the new public key for the login beside Access to Console into authorized_keys on the local disk. On Ubuntu the file is /home/ubuntu/.ssh/authorized_keys, and when the login label names another account, use that account’s home directory.
Replace PUBLIC_KEY with the OpenSSH public key on one line.
The > operator replaces the file, so keys already in it stop authenticating.
3

Set ownership and permissions

Set ownership and modes, then run sync before the reboot:
Keep /home/ubuntu at mode 750, because SSH succeeded with that mode on the Ubuntu image.
4

Reboot the server

Reboot into the default GRUB entry:
5

Confirm SSH access

From a client that holds the matching private key, connect with the login from the server page:
Replacing authorized_keys makes the previous private key fail with Permission denied (publickey).
Add multiple SSH keys at creation time. Set a console password in user data for a Virtual Machine or a Bare Metal server so the console opens without the SSH key.