Learn how to replace your SSH keys if you have lost access to your server.
If you are using SSH keys to connect to your server, losing your private SSH key could mean losing access to your server altogether.
However, you can still connect to your server via the OVHcloud rescue mode, which allows you to log in with a provisional password and modify your files.
This tutorial is designed to help you as much as possible with common tasks. If you are having difficulty performing these actions, please contact a specialized service provider. OVHcloud can't provide you with technical support in this regard.
Requirements
- a dedicated server or a VPS in your OVHcloud account
- access to the OVHcloud Control Panel
Instructions
Step 1: Create a new key pair
Create a new SSH key pair on your device, as described in the first part of the SSH key guide.
Step 2: Access your server in rescue mode and replace the key
Follow the steps in the rescue mode guide to connect to your server and mount your partitions:
To proceed, your system partition must be mounted and you must have write access to your file system.
By following the guides linked above, you should have entered a version of the following command into the rescue mode shell:
The exact command is dependent on the mountpoint you used. For example, if you have mounted your partition at /mnt
, it would be the following:
After completing these steps using the rescue mode guides linked above, you can now modify your SSH key.
When you have access to your files, open the "authorized_keys" file concerned with a text editor. This file stores SSH keys and is located in the home
folder of the user with which you connect to your server. (Replace "USER_NAME" with your actual user name.)
Copy and paste your new public key (created in step 1) into the file. It should look similar to the following example:
For security reasons, delete the obsolete "old" key string from the file. Save your changes and exit the editor.
You have now access to the server with your new SSH key pair.
Go further
For more information and tutorials, please see our other Dedicated Server support guides or explore the guides for other OVHcloud products and services.