Basic script to rotate ssh keys on remote server

This commit is contained in:
Clemens Schwaighofer
2024-05-14 11:34:16 +09:00
parent b8cfc1b700
commit cba0f964e7
9 changed files with 253 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
#!/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__