Posts

Showing posts from August, 2018

Shell script to add a public key to server and provide sudo privillege for that user.

#!/bin/bash #function which contains the ssh public key for user admin to add in the servers and another function to check if key already exists #If you want to add your user key, replace the admin with your username and add your ssh key to the section shown below. ################################################################## admin_keyexist_check() { if grep -q "******ssh key goes here******admin@<serverhostname>" /home/admin/.ssh/authorized_keys; then     echo " The ssh key already exists and is shown below...!!"        grep -i "admin" /home/admin/.ssh/authorized_keys     echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"     echo "Removing this shell script now...!!"     rm -fv $0     exit else     echo " The ssh key doesn't exists...!! We will add it...!!"     echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" fi } ####

EC2 instance listing using python boto3

#Purpose : To list all the AWS EC2 instances in the specified region. #The script assume that you have a working aws cli configured with privilege to access the aws ec2 instances. #!/usr/bin/env python import boto3 import sys import time region_name = raw_input('Enter aws region for which you want to get the details of the EC2 Instance [sample : us-east-1]: ') print (region_name, type(region_name)) time.sleep(5) ec2 = boto3.resource('ec2', globals()['region_name']) for instance in ec2.instances.all():     print instance.id, instance.state, instance.private_ip_address, instance.public_ip_address, instance.tags