- Documentation
Elastic Compute Service
Elastic Compute Service
User Guide
Security
Passwords and key pairs
Key pairs
Adding or replacing key pairs within instance
Key pairs
Adding or replacing key pairs within instance
Adding or replacing key pairs within instance
You can associate a Linux instance with only one key pair in the console. Within a Linux instance, you can manually edit the ~/.ssh/authorized_keys file to add multiple key pairs to the instance. This way, you can log in to the instance by using different key pairs. You can also refer to the following steps to replace the existing key pairs.
tip
- After you replace or delete a key pair within an instance, the key pair is disassociated from the instance. To permanently delete the key pair, you need to disassociate the key pair from the instance in the console and make sure that the key pair is not associated with any other instance. For information about how to disassociate a key pair from an instance in the console, see Disassociating key pairs from instances.
Prerequisite
Procedure
- Execute the following command to open the ~/.ssh/authorized_keys file.
- vim .ssh/authorized_keys
- Press i to enter the edit mode.
- Add or replace public key information.
- Add public key information: Add new public key information below the existing public key information. This way, you can log in to the same instance by using multiple key pairs.
- If the public key file contains multiple public keys, you can log in to the instance by using any corresponding private key.
- Replace public key information: Delete the existing public key information and add new public key information. That is, associate a new key pair with the instance.
- You can also directly delete the existing public key information to disassociate the key pair from the instance.
- Press Esc to exit the edit mode, enter :wq, and then press Enter to save and exit the file.
Result verification
After you complete the above operations within the instance, if you can log in to the instance by using the new private key, the key pair has been added or replaced.
Last updated: 2025.09.09 15:59:22