Delete SSH Keys Command for Linux and Unix

www.laut‮rut‬i.com
Delete SSH Keys Command for Linux and Unix

To delete SSH keys on a Linux or Unix system, you can use the following steps:

  1. First, locate the user's public and private keys. On most systems, the user's public key is stored in the ~/.ssh/authorized_keys file, and the private key is stored in the ~/.ssh/id_rsa file.

  2. Remove the user's public key from the authorized_keys file by deleting the line that contains the key. This will prevent the user from using their public key to authenticate with the server.

  3. Delete the user's private key file by using the rm command. For example, to delete the user's private key file, you can use the following command:

rm ~/.ssh/id_rsa

This will delete the id_rsa file, which contains the user's private key.

Keep in mind that deleting the user's SSH keys will not delete the user's files or data. If you want to delete the user's files, you will need to do so manually.

It is also a good idea to back up the user's keys and data before deleting them, in case you need to restore the user's access at a later time.

To delete SSH keys for multiple users, you can use a script to automate the process. For example, you can use a Bash script to loop through a list of users and delete their SSH keys, like this:

#!/bin/bash

# Read the list of users from a file
while read user; do
  # Remove the user's public key from the authorized_keys file
  sed -i "/$user/d" ~/.ssh/authorized_keys

  # Delete the user's private key file
  rm ~/.ssh/$user
done < users.txt

This script reads the list of users from a file called users.txt, and for each user it removes the user's public key from the authorized_keys file and deletes the user's private key file. You can modify this script to fit your specific needs.

Created Time:2017-10-28 14:02:27  Author:lautturi