Basic script to rotate ssh keys on remote server
This commit is contained in:
29
bin/remove-old-ssh-keys.sh
Normal file
29
bin/remove-old-ssh-keys.sh
Normal 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__
|
||||
Reference in New Issue
Block a user