Skip to content

Instantly share code, notes, and snippets.

@lvnilesh
Forked from jkobie/.ssh config
Last active January 15, 2020 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvnilesh/5e86aae56ae8fdc290af6c74f301a746 to your computer and use it in GitHub Desktop.
Save lvnilesh/5e86aae56ae8fdc290af6c74f301a746 to your computer and use it in GitHub Desktop.
Script to create Cloud Genius workstation from a linux computer
# Created on Mon Jan 13 19:16:24 PST 2020
Host CloudGenius
HostName ec2-52-24-156-230.us-west-2.compute.amazonaws.com
ForwardAgent yes
User ubuntu
StrictHostKeyChecking no
IdentityFile /home/jkobie/.ssh/DoNotUseThisKey-CloudGeniusOnly.pem
Host ec2-52-24-156-230.us-west-2.compute.amazonaws.com
HostName ec2-52-24-156-230.us-west-2.compute.amazonaws.com
IdentityFile /home/jkobie/.ssh/DoNotUseThisKey-CloudGeniusOnly.pem
User ubuntu
instance_response=$(aws ec2 run-instances \
--image-id ami-06d51e91cea0dac8d \
--count 1 \
--instance-type t2.micro \
--key-name DoNotUseThisKey-CloudGeniusOnly \
--security-groups DoNotUseThisSG-CloudGeniusOnly \
--user-data file://provision.txt \
--block-device-mappings 'DeviceName=/dev/xvdf,Ebs={VolumeSize=256,VolumeType=gp2,DeleteOnTermination=false,Encrypted=true}' \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value="DontMessWith Cloud Genius Workstation"}]' 'ResourceType=volume,Tags=[{Key=Name,Value="Disk for Cloud Genius"}]')
sleep 60
instanceId=$(echo -e "$instance_response" | jq -r '.Instances[] | .InstanceId' | tr -d '"')
PublicIpAddress=$(aws ec2 describe-instances \
--instance-id $instanceId | jq -r '.Reservations[] | .Instances[] | .PublicIpAddress' | tr -d '"')
rm -rf config
cat <<EOF >config
# Created on $(date)
Host CloudGenius
HostName $PublicIpAddress
ForwardAgent yes
User ubuntu
StrictHostKeyChecking no
IdentityFile ./.ssh/CloudGenius
EOF
mv -f config ~/.ssh/config
rm -rf provision.txt
~/.ssh/config
yes y | ssh-keygen -t rsa -N "" -C "CloudGenius" -f ~/.ssh/CloudGenius > /dev/null
aws --profile beacloud ec2 delete-key-pair --key-name DoNotUseThisKey-CloudGeniusOnly
aws --profile beacloud ec2 import-key-pair --key-name "DoNotUseThisKey-CloudGeniusOnly" --public-key-material file://~/.ssh/CloudGenius.pub
aws --profile beacloud ec2 delete-security-group --group-name DoNotUseThisSG-CloudGeniusOnly > /dev/null 2>&1
security_response=$(aws --profile beacloud ec2 create-security-group \
--group-name "DoNotUseThisSG-CloudGeniusOnly" \
--description "DoNotUseThisSG-CloudGeniusOnly security group" \
--output json)
groupId=$(echo -e "$security_response" | jq '.GroupId' | tr -d '"')
aws ec2 create-tags \
--resources "$groupId" \
--tags Key=Name,Value="DoNotUseThisSG-CloudGeniusOnly"
security_response2=$(aws --profile beacloud ec2 authorize-security-group-ingress \
--group-id "$groupId" \
--protocol tcp --port 22 \
--cidr "0.0.0.0/0")
rm -rf provision.txt
curl -O https://s3-us-west-2.amazonaws.com/cloudgeniuscode/provision.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment