Experience: is what you get soon after you need it.

Experience: is what you get soon after you need it.

****************Got the opportunity to pen a Book on Database Cloud Services.......More details to follow.***************

Title : Database Cloud Revealed
Publisher : Apress
Release Date : Jan-2021

**********************************************************************************


My Cloud Certifications:

AWS Certified Solutions Architect Associate

Azure Certified Architect Expert

Azure Certified Architect

Azure Certified Administrator

Oracle Cloud Infrastructure 2018 Certified Architect Associate.

Oracle Cloud Infrastructure Classic 2018 Certified Architect Associate.

Oracle Database Cloud Administrator Certified Professional.

Oracle Database Cloud Service Operations Certified Associate.

Search This Blog

Thursday, June 11, 2020

How to update ssh key on a cloud VM

It happens that someone created a VM with a key and either that person isn't there anymore or forgot to share the key with others or somehow lost the key altogether. Whatever the case might be in the below blog post you will see how to update the ssh key in order to login into the VM.

For AWS:

Generate new key pair with your favorite tools.
Ex:- using openssh

samshaik@shaikprod:~$ ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/samshaik/.ssh/id_rsa): cloud-key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in cloud-key.
Your public key has been saved in cloud-key.pub.
The key fingerprint is:
SHA256:GJk8yaVsFSNxquyVLwmR6uGMxzslniA0TMQ1Ib9AO8g samshaik@shaikprod
The key's randomart image is:
+---[RSA 2048]----+
|o+.+. o.*.       |
|+o+ .= @ .       |
|+E .o &          |
| +oo.+ =         |
|. +.+ + S        |
|o*.o.o o         |
|oo*+. o .        |
| .+.   .         |
|  ..             |
+----[SHA256]-----+


Now this will create two keys (public/private) in the specified path.

samshaik@shaikprod:~$ ls -lrt ~/.ssh/cloud-key*
-rw------- 1 samshaik samshaik 1766 Jun  9 14:44 /home/samshaik/.ssh/cloud-key
-rw-r--r-- 1 samshaik samshaik  400 Jun  9 14:44 /home/samshaik/.ssh/cloud-key.pub


1) Now stop the VM
2) Include the below code snippet in the user data dialog box as follows:
Select instance --> Actions --> Instance Settings then choose View/Change User Data

Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [users-groups, once]
users:
  - name: username  (name of the user you want to change the key for ex:-ec2-user)
    ssh-authorized-keys: 
    - PublicKeypair (No quotes required and make sure you have dash at the begining)

For AWS:



3) Start the instance
Now try ssh into the instance using the updated key.


Azure:

In Azure select the VM from the left menu --> Support + Troubleshooting --> Reset Password

Here you can either create a new user/update existing user password or ssh keys










































In Oracle Cloud:









Thursday, July 25, 2019

Azure move pagefile and change drive letter for D drive



In Azure on windows VMs, D:\ drive is reserved for pagefile and any data you store on this drive will be deleted. But there are few apps or you have jobs on your on-prem that have been hard coded to use the D drive as data disk. Rather changing the drive path in your jobs it is easy to change the pagefile drive to a different drive.



So How do we move the pagefile to a different drive and rename the D drive to a drive.





Temporarily move pagefile.sys to C drive

  1. Connect to the virtual machine.
  2. Right-click the Start menu and select System.
  3. In the left-hand menu, select Advanced system settings.
  4. In the Performance section, select Settings.
  5. Select the Advanced tab.
  6. In the Virtual memory section, select Change.
  7. Select the C drive and then click System managed size and then click Set.
  8. Select the D drive and then click No paging file and then click Set.
  9. Click Apply. You will get a warning that the computer needs to be restarted for the changes to take affect.
  10. Restart the virtual machine.

Change the drive letters

  1. Once the VM restarts, log back on to the VM.
  2. Click the Start menu and type diskmgmt.msc and hit Enter. Disk Management will start.
  3. Right-click on D, the Temporary Storage drive, and select Change Drive Letter and Paths.
  4. Under Drive letter, select a new drive such as T and then click OK.
  5. Right-click on the data disk, and select Change Drive Letter and Paths.
  6. Under Drive letter, select drive D and then click OK.


Move pagefile.sys back to the temporary storage drive

  1. Right-click the Start menu and select System
  2. In the left-hand menu, select Advanced system settings.
  3. In the Performance section, select Settings.
  4. Select the Advanced tab.
  5. In the Virtual memory section, select Change.
  6. Select the OS drive C and click No paging file and then click Set.
  7. Select the temporary storage drive T and then click System managed size and then click Set.
  8. Click Apply. You will get a warning that the computer needs to be restarted for the changes to take affect.
  9. Restart the virtual machine.


Sunday, June 2, 2019

AWS Take block volume snapshots at regular intervals


Now using Data Lifecycle manager you can take block volume snapshots at regular intervals without the need of custom scripts and lambda functions.




















Under block volumes -> Life Cycle Manager --> Create Policy





Give a policy Name
You can choose either instance level snapshots (which includes all the EBS volumes attached to the instance) or individual block level volumes.

Pick a schedule:
You can  pick a window anywhere between 2hrs and 12hrs 

Retention:
How many snapshots you want to retain, AFAIK limit is 1000 snapshots and it will overwrite the oldest snapshot.

















Tags:
Pick any tags that you want to have for the snapshots.






































IAM Role:

Pick a role or create a new role with the below policy:

{
  "Version": "2018-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:CreateSnapshot",
        "ec2:DeleteSnapshot",
        "ec2:DescribeVolumes",
        "ec2:DescribeSnapshots"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:CreateTags"
      ],
      "Resource": "arn:aws:ec2:*::snapshot/*"
    }
  ]
}


Enable the policy
























AWS Create Images from EBS Snapshots


You can take block volume snapshots for various reasons like for backup/restore, create golden images, create a custom image which will serve for future auto scaling launch templates and may be for disaster recovery purposes (We will see in a later post on how to take the incremental snapshots on regular intervals using Life cycle manager)

In this post we will cover how to take block volume snapshots and create a custom image from this snapshot.

Step-1:
Go to EBS Volumes and create snapshot:


It may take some time for the initial snapshot to complete based on the amount of size of storage volume






Step-2:

From the snapshots plane, go to actions and select "create Image", this will create a custom AMI based on the snapshot that we just took.














Step-3:

Now go to Images  and you should see the image you just created in step-2




Step-4:

You can now launch a EC2 instance using the private image you just created.















ssh: connect to host XX.XX.XX.XX port 22: Connection refused while connecting to Guest OS on Virtual Box

Issue:
While connecting from Windows - 10 to Guest OS - Oracle Linux -7.1  on Oracle Virtual Box - 5.2, you may get the below error.
ssh: connect to host XX.XX.XX.XX port 22: Connection refused


shaikprod@shaikprod ~
$ ping 192.168.56.1

Pinging 192.168.56.1 with 32 bytes of data:
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128
Reply from 192.168.56.1: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.56.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

shaikprod@shaikprod ~
$ ssh 192.168.56.1
ssh: connect to host 192.168.56.1 port 22: Connection refused

shaikprod@shaikprod ~
$ ssh 192.168.56.1
ssh: connect to host 192.168.56.1 port 22: Connection refused



Fix:
Enable port forwarding on the NAT -Network from the Oracle Virtual Box