From 9bad95a31177430bfac114fedd413e1ae40baaf4 Mon Sep 17 00:00:00 2001 From: andre Date: Sat, 29 Nov 2025 22:45:29 +0100 Subject: [PATCH] =?UTF-8?q?rootfs/home/andre/bash=5Fextensions/arg=5Fssh.b?= =?UTF-8?q?ash=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/andre/bash_extensions/arg_ssh.bash | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 rootfs/home/andre/bash_extensions/arg_ssh.bash diff --git a/rootfs/home/andre/bash_extensions/arg_ssh.bash b/rootfs/home/andre/bash_extensions/arg_ssh.bash new file mode 100644 index 0000000..1096a9e --- /dev/null +++ b/rootfs/home/andre/bash_extensions/arg_ssh.bash @@ -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 +} +