/ Scripts / Menu / menu-ssh.sh
menu-ssh.sh
  1  #!/bin/bash
  2  
  3  # shellcheck source=./Scripts/defaults.sh
  4  . "$HOME"/RoninDojo/Scripts/defaults.sh
  5  
  6  # shellcheck source=./Scripts/functions.sh
  7  . "$HOME"/RoninDojo/Scripts/functions.sh
  8  
  9  _load_user_conf
 10  
 11  OPTIONS=(1 "Start"
 12           2 "Stop"
 13           3 "Restart"
 14           4 "Enable Public Key Authentication"
 15           5 "Disable Public Key Authentication"
 16           6 "Add Public Key"
 17           7 "Delete Public Key"
 18           8 "Go Back")
 19  
 20  CHOICE=$(dialog --clear \
 21                  --title "$TITLE" \
 22                  --menu "$MENU" \
 23                  "$HEIGHT" "$WIDTH" "$CHOICE_HEIGHT" \
 24                  "${OPTIONS[@]}" \
 25                  2>&1 >/dev/tty)
 26  
 27  clear
 28  case $CHOICE in
 29      1)
 30          _print_message "Starting SSH..."
 31  
 32          if systemctl is-active --quiet sshd; then
 33              sudo systemctl start --quiet sshd
 34          else
 35              _print_message "SSH already started..."
 36          fi
 37  
 38          _pause continue
 39          bash -c "${ronin_ssh_menu}"
 40          ;;
 41      2)
 42          printf "%s\n***\nStopping SSH...\n***%s\n" "${red}" "${nc}"
 43  
 44          if systemctl is-active --quiet sshd; then
 45              sudo systemctl stop --quiet sshd
 46          else
 47              printf "%s\n***\nSSH already stopped...\n***%s\n" "${red}" "${nc}"
 48          fi
 49  
 50          _pause continue
 51          bash -c "${ronin_ssh_menu}"
 52          ;;
 53      3)
 54          printf "%s\n***\nRestarting SSH...\n***%s\n" "${red}" "${nc}"
 55  
 56          sudo systemctl reload-or-restart --quiet sshd
 57  
 58          _pause continue
 59          bash -c "${ronin_ssh_menu}"
 60          ;;
 61      4)
 62          if _ssh_key_authentication enable; then
 63              if _ssh_key_authentication add-ssh-key; then
 64                  printf "%s\n***\nVerify connection now...\n***%s\n" "${red}" "${nc}"
 65  
 66                  _pause continue
 67  
 68                  if ! _yes_or_no "Did connection work?"; then
 69                      _ssh_key_authentication disable
 70                  fi
 71  
 72                  printf "%s\n***\nReturning to menu...\n***%s\n" "${red}" "${nc}"
 73              fi
 74          fi
 75  
 76          _pause continue
 77          # Return to menu
 78          bash -c "${ronin_ssh_menu}"
 79          ;;
 80      5)
 81          if ! sudo grep -q "UsePAM no" /etc/ssh/sshd_config; then
 82              printf "%s\n***\nSSH Key Authentication not enabled! Returning to menu...\n***%s\n" "${red}" "${nc}"
 83          else
 84              printf "%s\n***\nDisabling SSH Key Authentication...\n***%s\n\n" "${red}" "${nc}"
 85  
 86              if _yes_or_no "${red}Do you wish to continue?${nc}"; then
 87                  _ssh_key_authentication disable
 88              fi
 89          fi
 90  
 91          _pause continue
 92          bash -c "${ronin_ssh_menu}"
 93          ;;
 94      6)
 95          if ! sudo grep -q "UsePAM no" /etc/ssh/sshd_config; then
 96              printf "%s\n***\nSSH Key Authentication not enabled! Returning to menu...\n***%s\n" "${red}" "${nc}"
 97          else
 98              if _ssh_key_authentication add-ssh-key; then
 99                  printf "%s\n***\nKey successfully added... Returning to menu...\n***%s\n" "${red}" "${nc}"
100              else
101                  printf "%s\n***\nKey already exists... Returning to menu...\n***%s\n" "${red}" "${nc}"
102              fi
103          fi
104  
105          _pause continue
106          bash -c "${ronin_ssh_menu}"
107          ;;
108      7)
109          if ! sudo grep -q "UsePAM no" /etc/ssh/sshd_config; then
110              printf "%s\n***\nSSH Key Authentication not enabled! Returning to menu...\n***%s\n" "${red}" "${nc}"
111          else
112              if _ssh_key_authentication del-ssh-key; then
113                  printf "%s\n***\nKey has been removed... Returning to menu\n***%s\n" "${red}" "${nc}"
114              else
115                  printf "%s\n***\nKey not available to delete... Returning to menu\n***%s\n" "${red}" "${nc}"
116              fi
117          fi
118  
119          _pause continue
120          bash -c "${ronin_ssh_menu}"
121          ;;
122      8)
123          bash -c "${ronin_networking_menu}"
124          ;;
125  esac
126  
127  exit