Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to ssh into an amazon or other remote host. I made this script to have a single shortcut on my desktop to use in order to load a routine that would simplify establishing an ssh pipe to our remote servers, in this snippet 2 servers are used, but as you can see, it can be scaled up easily by adding more options/cases in the code. Happy…
#!/bin/bash
# Bash script to ssh into an amazon or other remote host. I made this script to have a single shortcut on my desktop to use in order to load a routine that would simplify establishing an ssh pipe to our remote servers, in this snippet 2 servers are used, but as you can see, it can be scaled up easily by adding more options/cases in the code. Happy Coding!
# Author: Jorge Morales
#UPDATE THESE VARIABLES WHENEVER THERE ARE CHANGES
test_server="TEST_SERVER_HOST_ADDRESS"
production_server="PRODUCTION_SERVER_HOST_ADDRESS"
pathToCertificate="PATH_TO_KEYFILE"
echo "Type 1 to connect to Test server."
echo "Type 2 to connect to Production server."
echo "So..."
while true; do
read -p "Which server will you connect to today?" choice
case $choice in
[1]* ) echo "We will connect you to the test server now..."; ssh -i $pathToCertificate $test_server; break;;
[2]* ) echo "We will connect you to the production server now..."; ssh -i $pathToCertificate $production_server; break;;
* ) echo "An unrecognized input was entered. It's either 1 or 2. Those are your choices. Don't get too creative here... LOL!";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.