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.
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.
Time: 5 minutes
Remove the SSH key
- Log in to your server via SSH.
- Switch to the root user:
sudo su -
- 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.
- 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.
- Make sure you are still logged in as root.
- Use the passwd command to change your user's password:
passwd user's username
- Enter a new password, and then confirm it.
Your user's password is now updated.