Last active
November 16, 2017 21:44
-
-
Save drbh/f336e3b7d92cf19681e2635aad94c8ab to your computer and use it in GitHub Desktop.
Easily SSH into an instance and forward two ports to allow access on your local machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Ask the user for their name | |
echo 'Hello, I will help you connect to your EC2 instance. | |
You will need 3 pieces of information: | |
Username | |
Host Address | |
Path to key file\n\n' | |
read -n 1 -s -r -p "[Press any key to continue]" | |
echo '\n\n' | |
echo 'Username (OS specific. eg Ubuntu:ubuntu AmazonLinux:ec2-user)' | |
read username | |
echo 'Host-name (address eg. ec2-35-182-252-128.ca-central-1.compute.amazonaws.com)' | |
read host | |
echo 'Key Location (path eg. ~/Keys/your-key.pem)' | |
read key | |
echo 'Enter port 1 (from/to)' | |
read port1 | |
echo 'Enter port 2 (from/to)' | |
read port2 | |
chmod 400 $key | |
# echo 'ssh -i' $key '-N -L' $port':'$host':'$port $username@$host | |
ssh -X -i $key -N -L $port1:$host:$port1 $username@$host -v & | |
ssh -X -i $key -N -L $port2:$host:$port2 $username@$host -v | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment