-
-
Save lvnilesh/5e86aae56ae8fdc290af6c74f301a746 to your computer and use it in GitHub Desktop.
Script to create Cloud Genius workstation from a linux computer
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
# 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 |
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
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 |
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
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