Skip to main content

AWS Command line Tasks - Create SSH key pair, security group, Allow connection to a port

We need a working aws cli configured to use the following commands.

To create an SSH pem file.

aws ec2 create-key-pair --region us-east-1 --key-name mysshkey --output text > mysshkey.pem 

region :  The region in which the ssh pem file is getting created.
Here we are saving the pem file in our linux machine as the name mysshkey.pem 

Modify the permission of the pem file.

chmod 400 mysshkey.pem 

To create a security group.

aws ec2 create-security-group --region us-east-1 --group-name work_project --description "Project_for_work" --vpc-id vpc-12345 

group name - It is the name that we are going to give for the security group
description - The description that we are going to give for the security group

To allow connection to a port

aws ec2 --region us-east-1 authorize-security-group-ingress --group-id sg-12345 --protocol tcp --port 22 --cidr
aws ec2 --region us-east-1 authorize-security-group-ingress --group-id sg-12345 --protocol tcp --port 22 --cidr

The port :--protocol tcp --port <port number here>
Allowing IP or IP range : --cidr <IP range or the IP>

Popular posts from this blog

Qmail cheat sheet

1) To check the mail queue in plesk from command line, you can use the command :


2) You can examine the queue with qmail-qread.


3) From the qread command you get the message id . In the above example , let us assume one of the id is 524514 . Now you can find the file holding the email in/var/qmail/queue with find command.

# find /var/qmail/queue -iname 524514


/var/qmail/queue/mess/22/524514 (mail headers)


4) From the mail header you get the IP address

vi /var/qmail/queue/mess/22/524514


Shortcut for the cool guys

find /var/qmail/queue -iname queu_id | grep mess | xargs less


4) If you wish …

Logical volume vmxxxx_img is used by another device - Error on LVM removal

Hi Folks,

I've faced error while trying to remove an LVM from the server.

The exact LVM error will be "Logical volume vmxxxx_img is used by another device" on executing the lvremove command.

Feel free to remove the following steps to remove the LVM from the server.

Note: Please remember to replace <id> with your VMID in the below section.

dmsetup ls dmsetup info -c xen-vm<id>_img dmsetup remove xen-vm<id>_img lvremove -f /dev/xen/vm<id>_img ----------------------------------------------------------

File system corrupted on the OpenVZ container.

It happens rarely but when it does, it is hard to handle. The OpenVZ VM's are usually stable in nature, but I've encountered situations where OpenVZ VM was showing file system error and was refusing to start.

You can follow the below steps to recover the VM.

1. ~# vzctl stop ctid

2. # ploop mount /vz/private/ctid/root.hdd/DiskDescriptor.xml
3. now do a df -h and you will get the ploop id for the VM.
4. fdisk -l /dev/ploop12345
5. e2fsck /dev/ploop12345p1
6. ploop umount -d /dev/ploop12345
7. vzctl start ctid