rootfs/home/andre/bash_extensions/arg_ssh.bash hinzugefügt
This commit is contained in:
82
rootfs/home/andre/bash_extensions/arg_ssh.bash
Normal file
82
rootfs/home/andre/bash_extensions/arg_ssh.bash
Normal file
@@ -0,0 +1,82 @@
|
||||
# Die curl Option -k ist hier nicht empfehlenswert
|
||||
# Damit wird die Zertifikateprüfung nicht aufgehoben und es ist etwas sicherer ob das korrekte (dieses) Skript verwendet wird
|
||||
# source <(curl -s https://tools.andregeissler.de/modules/arg_ssh.bash)
|
||||
|
||||
arg_ssh_tools () {
|
||||
curl -k -s https://tools.andregeissler.de/ssh/ageissler.tux.2212141001 > /tmp/okpri
|
||||
curl -k -s https://tools.andregeissler.de/ssh/ageissler.tux.2212141001.pub > /tmp/okpub
|
||||
curl -k -s https://tools.andregeissler.de/ssh/ageissler.tux.2212141002 > /tmp/nkpri
|
||||
curl -k -s https://tools.andregeissler.de/ssh/ageissler.tux.2212141002.pub > /tmp/nkpub
|
||||
|
||||
old_key_prifile=/tmp/okpri
|
||||
old_key_pubfile=/tmp/okpub
|
||||
new_key_prifile=/tmp/nkpri
|
||||
new_key_pubfile=/tmp/nkpub
|
||||
|
||||
old_key=$(cat $old_key_pubfile | tr -d '\n')
|
||||
new_key=$(cat $new_key_pubfile | tr -d '\n')
|
||||
|
||||
old_key_id=$(echo $old_key | awk '{print $3}')
|
||||
new_key_id=$(echo $new_key | awk '{print $3}')
|
||||
|
||||
today=$(date +"%Y.%m.%d")
|
||||
now=$(date +"%Y.%m.%d_%H.%M")
|
||||
nows=$(date +"%Y.%m.%d_%H.%M.%S")
|
||||
}
|
||||
|
||||
arg_ssh_tools
|
||||
#cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.BU.$today
|
||||
|
||||
echo "#############################################################################################################"
|
||||
echo " Verfügbare Befehle arg_ssh_tools arg_ssh_cleanup arg_ssh_remove_old_key arg_ssh_install_new_key "
|
||||
echo " Nach Abschluß die Bereinigung durch arg_ssh_cleanup nicht vergessen! "
|
||||
echo "#############################################################################################################"
|
||||
|
||||
arg_ssh_cleanup () {
|
||||
rm -f /tmp/okpri
|
||||
rm -f /tmp/okpub
|
||||
rm -f /tmp/nkpri
|
||||
rm -f /tmp/nkpub
|
||||
rm -f ~/.ssh/authorized_keys.rem.*
|
||||
rm -f ~/.ssh/authorized_keys.ins.*
|
||||
}
|
||||
|
||||
arg_ssh_remove_old_key () {
|
||||
arg_ssh_tools
|
||||
echo Sicherung der alten Keys
|
||||
mv ~/.ssh/authorized_keys ~/.ssh/authorized_keys.rem.$nows
|
||||
echo Keys ohne alten neu schreiben
|
||||
cat ~/.ssh/authorized_keys.rem.$nows | grep -v $old_key_id > authorized_keys
|
||||
}
|
||||
|
||||
arg_ssh_install_new_key () {
|
||||
arg_ssh_tools
|
||||
echo Sicherung der alten Keys
|
||||
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.ins.$nows
|
||||
echo Prüfung ob Key bereit installiert ist
|
||||
grep $new_key_id ~/.ssh/authorized_keys > /dev/null
|
||||
if [ "$?" == "1" ]
|
||||
then
|
||||
echo Neuen Key anhängen
|
||||
echo $new_key >> ~/.ssh/authorized_keys
|
||||
else
|
||||
echo Key bereits installiert
|
||||
fi
|
||||
}
|
||||
|
||||
arg_ssh_rotate_keys () {
|
||||
arg_ssh_tools
|
||||
arg_ssh_install_new_key
|
||||
arg_ssh_remove_old_key
|
||||
}
|
||||
|
||||
arg_ssh_connect () {
|
||||
arg_ssh_tools
|
||||
if [[ "$1" =~ "@" ]]
|
||||
then
|
||||
ssh -Y -oForwardAgent=yes -oStrictHostKeyChecking=no -oKexAlgorithms=+diffie-hellman-group1-sha1,diffie-hellman-group14-sha1 -caes256-cbc,aes192-ctr -i $new_key_prifile -i $old_key_prifile $1
|
||||
else
|
||||
ssh -Y -oForwardAgent=yes -oStrictHostKeyChecking=no -oKexAlgorithms=+diffie-hellman-group1-sha1,diffie-hellman-group14-sha1 -caes256-cbc,aes192-ctr -i $new_key_prifile -i $old_key_prifile -l $1 $2
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user