#!/bin/bash /usr/lib/turtle/turtle_module VERSION="1.2" DESCRIPTION="SSH Key Manager" EXECUTABLE="0" CONF=/tmp/keymanager.form : ${DIALOG_OK=0} : ${DIALOG_CANCEL=1} : ${DIALOG_HELP=2} : ${DIALOG_EXTRA=3} : ${DIALOG_ITEM_HELP=4} : ${DIALOG_ESC=255} function generate_key { dialog --title "Generate New SSH Key Pair?" \ --yesno "\nGenerate New SSH Key Pair?\n\n\ This will replace the existing key pair in /root/.ssh/\n\n\ Note: SSH sessions relying on this key pair will not authenticate until the new public key is copied to the\nremote server." \ 13 60 2>$CONF case $? in 0) rm -rf /root/.ssh/id_rsa* ssh-keygen -N "" -f /root/.ssh/id_rsa | dialog --programbox "Generating Key Pair (This will take a minute)" 20 60 dialog --title "Notice" --msgbox "SSH Key Pair Generated" 5 60 configure ;; 1) configure ;; esac } function copy_key { dialog --ok-label "Submit" \ --title "SSH Copy ID" \ --form "SSH Copy ID is a convient script which will copy the local SSH public key to a remote server.\n \n\ Host: Remote SSH Server.\n\ Port: Remote SSH Server Port (Typically 22).\n\ User: User on remote SSH server.\n \n" 17 60 3\ "Host:" 1 1 "$copy_host" 1 10 48 0 \ "Port:" 2 1 "$copy_port" 2 10 48 0 \ "User:" 3 1 "$copy_user" 3 10 48 0 \ 2>$CONF return=$? case $return in 0) cat $CONF | { read -r copy_host read -r copy_port read -r copy_user if [ -z "$copy_host" ]; then dialog --title "Notice" --msgbox "Host Required" 5 60; copy_key fi if [ -z "$copy_port" ]; then copy_port="22" fi if [ -z "$copy_user" ]; then dialog --title "Notice" --msgbox "User Required" 5 60; copy_key fi rm /tmp/empty_* &>/dev/null ssh-copy-id -i /root/.ssh/id_rsa.pub -p "$copy_port" "$copy_user"@"$copy_host" configure };; 1) configure;; 255) configure;; esac } function add_host { dialog --title "Notice" --msgbox "This function is deprecated and is now served by copy_key. This notice exists for documentation consistency. Please run copy_key." 8 60 configure } function review { touch /root/.ssh/known_hosts dialog --title "/root/.ssh/known_hosts" \ --editbox /root/.ssh/known_hosts 18 72\ 2>/dev/null configure } function configure { dialog --title "" --menu "" 15 60 5 \ "generate_key" "Generate new SSH key pair" \ "copy_key" "Copy public key to remote host" \ "add_host" "Add Remote host to local known_hosts" \ "review" "Review local known_hosts" \ "back" "Back" 2> $CONF result=$(cat $CONF && rm $CONF &>/dev/null) case $result in "generate_key") generate_key;; "copy_key") copy_key;; "add_host") add_host;; "review") review;; "back") exit;; esac }