Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## MD Harrington 11-05-2023 Time 13:45hrs
- ## Bash script to assist with generating ssh keys for git hub
- ## Add your SSH private key to the ssh-agent
- ## Copy key to clip board ready to paste into github
- ## Open page at Githubs address for doing this using default browser
- clear
- # ANSI color codes
- BLUE='\033[0;34m'
- GREEN='\033[0;32m'
- RED='\033[0;31m'
- YELLOW='\033[0;33m'
- MAGENTA='\033[0;35m'
- CYAN='\033[0;36m'
- NC='\033[0m' # No Color
- # Display header
- echo -e "${YELLOW}****************************************${NC}"
- echo -e "${BLUE}Creating SSH Keys by MD Harrington ${NC}"
- echo -e "${MAGENTA}$(date +"%Y-%m-%d %T")${NC}"
- echo -e "${YELLOW}****************************************${NC}"
- echo ""
- # Request email address and store in EMAIL variable
- read -p "Enter your email address: " EMAIL
- # Check if email address has been entered
- if [[ -z $EMAIL ]]; then
- echo -e "${RED}No email address entered.${NC} Exiting..."
- exit 1
- fi
- # Check if email address is valid
- if ! [[ "$EMAIL" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]]; then
- echo -e "${RED}Invalid email address entered.${NC} Exiting..."
- exit 1
- fi
- # Display menu options
- while true
- do
- echo -e "${YELLOW}***************${NC}"
- echo -e "${YELLOW}*${NC} ${GREEN}Menu Options${NC} ${YELLOW}*${NC}"
- echo -e "${YELLOW}***************${NC}"
- echo -e "${RED}${CYAN}1${NC}${RED}. Create ssh key${NC}"
- echo -e "${GREEN}${CYAN}2${NC}${GREEN}. Add your SSH private key to the ssh-agent${NC}"
- echo -e "${YELLOW}${CYAN}3${NC}${YELLOW}. Copy ssh key to clipboard${NC}"
- echo -e "${BLUE}${CYAN}4${NC}${BLUE}. Print ssh-key to terminal${NC}"
- echo -e "${MAGENTA}${CYAN}5${NC}${MAGENTA}. Add key to Git-Hub${NC}"
- echo -e "${CYAN}6${NC}. Exit menu"
- echo ""
- # Get user choice
- read -p "Enter your choice: " CHOICE
- # Perform action based on user choice
- case $CHOICE in
- 1) # Create ssh key
- ssh-keygen -t ed25519 -C $EMAIL
- ;;
- 2) # Add your SSH private key to the ssh-agent
- ssh-add ~/.ssh/id_ed25519
- ;;
- 3) # Copy ssh key to clipboard
- # Check if pbcopy is installed and install if not
- if ! command -v pbcopy &> /dev/null; then
- clear
- echo ""
- echo ""
- echo "***************** NOTE IMPORTANT !! IMPORTANT *****************************"
- echo -e "${YELLOW}This script requires pbcopy${NC}"
- echo -e "${RED}However pbcopy not found.${NC}"
- echo -e "${BLUE}Please use option 4 of menu and copy key direct from terminal.${NC}"
- echo "*******************************************************************************"
- else
- pbcopy < ~/.ssh/id_ed25519.pub
- echo "SSH key copied to clipboard"
- fi
- ;;
- 4) # Print ssh-key to terminal
- cat ~/.ssh/id_ed25519.pub
- ;;
- 5) # Add key to Git-Hub
- xdg-open https://github.com/settings/keys # opens webpage using default browser
- ;;
- 6) # Exit menu
- echo "Exiting menu..."
- exit 0
- ;;
- *) # Invalid choice
- echo -e "${RED}Invalid choice${NC}"
- ;;
- esac
- done
- echo ""
- echo "Hope this makes life far easier for you !"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement