Technology Encyclopedia Home >How to delete SSH keys from a cloud server?

How to delete SSH keys from a cloud server?

To delete SSH keys from a cloud server, follow these steps based on the operating system and access method:

1. For Linux-based Cloud Servers (via Terminal)

SSH keys are typically stored in the ~/.ssh/authorized_keys file for user accounts. To remove a key:

  • Step 1: Connect to the server via SSH:

    ssh username@server_ip
    
  • Step 2: Open the authorized_keys file:

    nano ~/.ssh/authorized_keys
    

    (Or use vim, vi, or any text editor.)

  • Step 3: Locate the key you want to delete (it starts with ssh-rsa or similar) and remove the entire line.

  • Step 4: Save the file and exit the editor.

Example:
If the key is:

ssh-rsa AAAAB3NzaC1yc2E... user@example.com  

Delete that entire line.

2. For Windows-based Cloud Servers (via RDP or PowerShell)

If the server uses OpenSSH (Windows 10/11 or Windows Server 2019+):

  • Step 1: Open PowerShell as Administrator.
  • Step 2: List authorized keys:
    Get-Content C:\Users\username\.ssh\authorized_keys
    
  • Step 3: Edit the file to remove the unwanted key:
    notepad C:\Users\username\.ssh\authorized_keys
    
    Delete the key line and save.

3. Using Tencent Cloud Console (for Root Access or Key Management)

If the SSH key was added via Tencent Cloud’s Key Pair feature:

  • Step 1: Log in to the Tencent Cloud Console.
  • Step 2: Navigate to CVM (Cloud Virtual Machine) > Key Pair Management.
  • Step 3: Select the key pair and click Delete (this removes the key from Tencent Cloud but does not remove it from existing servers).
  • Step 4: Manually delete the key from ~/.ssh/authorized_keys on the server if needed.

Note: Deleting a key pair from the console does not automatically remove it from servers where it was manually added.

4. Revoke Key Access Without Deleting the File

If you want to temporarily block a key, you can modify the sshd_config file (Linux):

sudo nano /etc/ssh/sshd_config  

Add or modify:

DenyUsers username  

Then restart SSH:

sudo systemctl restart sshd  

This prevents the user from logging in, even if the key exists.

For Tencent Cloud, you can also reset the instance password or disable login temporarily from the console if needed.