Files
SSH-Rotate-Keys/bin/remove-old-ssh-keys.sh
2024-05-14 11:34:16 +09:00

30 lines
939 B
Bash

#!/usr/bin/env bash
# base folder for all data
BASE_FOLDER=$(dirname "$(readlink -f "$0")")"/";
# config folder
CONFIG_BASE="${BASE_FOLDER}../config/";
# previous public key
SSH_PUBLIC_KEYS_PREVIOUS="${BASE_FOLDER}../ssh-public-keys/previous/";
# load config
if [ -f "${CONFIG_BASE}settings.ini" ]; then
source <(grep = "${CONFIG_BASE}settings.ini" | sed 's/ *= */=/g')
fi
# we must have "server_list" set and file must be in config folder
if [ ! -f "${CONFIG_BASE}${server_list}" ]; then
echo "Cannot find ${server_list} file in the config folder";
exit
fi
# find last public in remote server and remove it
for line in `cat "${CONFIG_BASE}${server_list}" | sed 1d`; do
hostname=$(echo "${line}" | cut -d "," -f 1)
# flags are current "M" for multi key, has other users public key in too
flags=$(echo "${line}" | cut -d "," -f 2)
echo "Remove previous key for: ${hostname}";
# find in master key and $admin user
done
# __END__