How to replace an SSH key pair
Objective
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 guide explains how to replace your SSH keys if you have lost access to your server.
OVHcloud is providing you with services for which you are responsible, with regard to their configuration and management. It is therefore your responsibility to ensure that they function correctly.
This guide is designed to assist you in common tasks as much as possible. Nevertheless, we recommend that you contact a specialist service provider or reach out to our community if you face difficulties or doubts concerning the administration, usage or implementation of services on a server.
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:
In order to proceed, your system partition must be mounted and you must have write access to your file system.
This means that you 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:
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.
Switch the boot mode back to "normal" and restart the server in your OVHcloud Control Panel. Refer to the rescue mode guide if necessary.
You have now access to the server with your new SSH key pair.
Go further
Join our community of users.