---
title: "How to replace a SSH key pair"
description: "Learn how to replace your SSH keys if you have lost access to your server."
url: https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/replacing-lost-ssh-key-pair
lang: en
---
> 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.

# How to replace a SSH key pair

**Learn how to replace your SSH keys if you have lost access to your server.**

If you are [using SSH keys](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/create-use-authentication-keys-ssh-connections-ovhcloud-server.md) 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

- A [dedicated server](https://us.ovhcloud.com/bare-metal/) or a [VPS](https://us.ovhcloud.com/vps/) in your OVHcloud account
- Access to the [OVHcloud Control Panel](https://manager.us.ovhcloud.com/)

 

## 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](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/create-use-authentication-keys-ssh-connections-ovhcloud-server.md).

 

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

- [Dedicated server rescue mode](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/rescue-mode.md#mounting-partitions-to-access-your-files)
- [VPS rescue mode](https://docs.us.ovhcloud.com/en/bare-metal-cloud/vps/recover-rescue-mode.md#mounting-the-partition-and-changing-the-root-password)

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:

```bash
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:

```bash
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.)

```bash
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:

```console
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](https://manager.us.ovhcloud.com/). Refer to the [rescue mode guide](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/rescue-mode.md) if necessary.

You have now access to the server with your new SSH key pair.

 

## Go further

Browse all the [Dedicated Servers guides](https://docs.us.ovhcloud.com/en/bare-metal-cloud/dedicated-servers/landing-page-dedicated-servers.md).

Browse the rest of the [OVHcloud US documentation](https://docs.us.ovhcloud.com/en/index.md) for guides on our other products and services.

Learn more about [Dedicated Servers](https://us.ovhcloud.com/bare-metal/) on the OVHcloud US website.
