For AI agents: the complete documentation index is available at https://docs.us.ovhcloud.com/en/llms.txt, the full documentation bundle is available at https://docs.us.ovhcloud.com/en/llms-full.txt, and this page is available as Markdown at https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/replacing-lost-ssh-key-pair.md.
  • English

How to replace a SSH key pair

View as Markdown

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.

Warning

NOTE: OVHcloud provides services for which you are responsible for their configuration and management. You are therefore responsible for their proper functioning.

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 cannot provide you with technical support in this regard.

 

Requirements

 

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:

chroot path/to/partition/mountpoint

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:

chroot /mnt/root

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 with a text editor. This file stores SSH keys and is located in the home folder of the user with whom you connect to your server. (Replace "USER_NAME" with your actual user name.)

nano /home/USER_NAME/.ssh/authorized_keys

Copy and paste your new public key (created in step 1) into the file. It should look similar to the following example:

ssh-rsa 1111111111122222222222333333333333444444444555555555556666666666
777777777778888888888999999900000000000000000000000000== old@sshkey
ssh-rsa AAAAAAAAABBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDEEEEEEEEE
EEFFFFFFFFFFFFFGGGGGGGGGGGGGhhhhhhhhhhhhhhhhhhhhhhhhhh== new@sshkey

For security reasons, delete the obsolete "old" key string from the file. Save your changes and exit the editor.

Warning

NOTE: 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

Browse all the Dedicated Servers guides.

Browse the rest of the OVHcloud US documentation for guides on our other products and services.

Learn more about Dedicated Servers on the OVHcloud US website.