Remove SSH keys from your server

You can remove a user's SSH key manually while keeping the user itself intact. This is useful in case an SSH private key gets lost or compromised.

Note: If you already removed the user with the -r flag, their SSH keys have already been deleted and you do not need to complete these steps.

Difficulty: 1
Time: 5 minutes

Remove the SSH key

  1. Log in to your server via SSH.
  2. Switch to the root user:
    sudo su -
  3. Find that user's home directory:
    echo ~user's username

    You will see your user's home directory. This is usually /home/user's username.
  4. Using this path, remove the .ssh folder from that user:
    rm -rf /home/user's username/.ssh

You have removed that user's SSH key.

Create a password

After you have removed the key, you must give this user a password or they will be unable to log in.

  1. Make sure you are still logged in as root.
  2. Use the passwd command to change your user's password:
    passwd user's username
  3. Enter a new password, and then confirm it.

Your user's password is now updated.

Next step

Add an SSH Key to an existing server

Czy ten artykuł był pomocny?
Thanks for your feedback. To speak with a customer service representative, please use the support phone number or chat option above.
Cieszymy się, że udało się nam pomóc! Czy coś jeszcze możemy dla Ciebie zrobić?
Przykro nam z tego powodu. Tell us what was confusing or why the solution didn’t solve your problem.