Cannot connect to Linux VM (Google Cloud Platform Compute Engine) - google-cloud-platform

I am running a ubuntu 18.04 VM on google cloud platform. I have had it working but now when I try to connect I get this error:
I am unsure what to do about this problem.

You need to add a firewall rule that allows tcp:22

Since you already tried using gcloud, double checked firewall rule and I suspect you did not change anything in the VM configuration, the easiest approach that you can do now is create a snapshot and move it to a new VM instance:
Go to Compute Engine section.
Then select “Snapshots” in the left menu.
Click “Create Snapshot”.
In “source disk” select your current VM instance, Encryption: automatic and provide the required information in the other fields.
Click “Create”.
After the snapshot is created you can go and use it to create a new VM. In the “Create instance” section do the following:
In “Boot Disk” click the “Change” button.
Click the “Snapshots” tab (upper right).
Select the previously created snapshot.
Click “select” and then “Create”.
You should be able to SSH into the new instance.

Related

Automate retrieving password from Ec2 windows instance that was launched from custom AMI

When the instance is launched from the custom AMI I could not retrieve password for the launched instance. This issue and resolution is discussed here and it worked.
These are the manual steps I performed:
Open the Amazon EC2 console, and then connect to the original Windows EC2 instance using Remote Desktop Protocol (RDP).
From the Windows Start menu, do the following:
For Windows Server 2008 through Windows Server 2012 R2, open EC2ConfigService Settings, and then choose the Image tab.
For Windows Server 2016 or later, open EC2 Launch Settings.
For Administrator Password, choose Random.
Select Shutdown without Sysprep *.
Select Yes.
Open the Amazon EC2 console, and then select Instances.
Wait until the instance state changes to Stopped, and then choose your instance.
Select Actions, Image, Create image.
For Image name, enter a name.
(Optional) For Image description, enter a description.
Choose Create image.
I wanted to know if steps from 1 to 5 can be automated?
The source instance has the following scripts, and wondering if any of these script will do the trick, if yes, then what parameter I need to pass
"C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SendWindowsIsReady.ps1 -Schedule",
"C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 -Schedule",
"C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SysprepInstance.ps1 -NoShutdown"

GCP API - How could you determine that a VM was created via Marketplace?

I'm trying to make an API call in Python (inside a Cloud Function) to do some various things and as part of the information I'd like to pass along is whether the VM was created from something in the Marketplace.
The use case is this: The user is in the GCP Console in Compute Engine. They click on Marketplace in the left column of the display which then brings up VMs to choose from. The user picks one (say "Ubuntu 20.4 LTS (Focal)"). The display shows information about the VM with a "Launch" button. When they click that, they are then taken to the "Create an instance" page and they continue making choices and eventually create the VM.
This creates a log entry that the client's security group checks inside of a cloud function. When I look at the log entry for beta.compute.instances.insert, I don't see anything about it being created via Marketplace. If I make an API call to get the instance, there's nothing in the object returned that shows that either. Anyone know of any way to determine this?
It depends on what you mean by "via Marketplace". In general, the Marketplace offer is usually a Deployment Manager template and an image in a public project (public projects are available only to partners publishing to Marketplace). So if you deploy a Marketplace VM solution you will have:
a VM with source image in some project outside your org; but this will also match VMs created manually using that image (does it match your "via Marketplace" definition?) and VMs created from custom images your individual users have access to. Hint: your service account assigned to function will also have access to all public images, but usually not to images shared between users.
Deployment Manager deployment - that's a nice one as such deployments have some marketplace-specific labels. The problem is that deployment metadata can be deleted without deleting the deployed resources. And there's the case you mentioned with some marketplace listings being just redirections to deploying a single VM.
I'm afraid there's no way to detect if an Ubuntu VM was deployed after visiting Marketplace, or after clicking add VM button or using CLI or terraform - for the GCE it was simply an API call to insert a new instance.

Setting up a server on Google Cloud Platform

I spun up a Ubuntu 16.04 VM on Google Cloud Platform and tried following steps one to three on setting the VM up.
Instead of ssh root#your_server_ip (step one), I just went to the console, clicked on the drop-down under the Connect column in "VM instances" and selected "Open in browser window". Then I followed steps two and three to create a new user and to give it root privileges.
Skipping the 'recommended' steps 4 and 5, I tried step 6 to do a test log in by activating the Cloud Shell. But ssh [user created in step 2]#your_server_ip, where your_server_ip is the "External IP" in the "VM instances" page results in "Permission denied (publickey)."
Why is this?
Martheen comment is right, you need to generate the ssh key pair in order to ssh.
As you are using the Google Cloud platform I will point you to the documentation related there.
You can use the GCP ways to connect to the instance here.
Other methods to connect you can find here.

How can I migrate ECS Instance across Dedicated Host

I have an Alibaba Cloud ECS and want to migrate across my Dedicated Host (DDH).
How can I do the same and Is there any limitation on the ECS.
I appreciate any assistance with this.
I think this documentation clarify how to do it enter link description here
Log on to the ECS console.
In the left-side navigation pane, click Instances.
Select a region.
Optional. In the upper-right corner of the instance list, click the Set Display Items icon, and on the dialog box, click Dedicated Host,and then click OK.
You can view the Dedicated Host column in the table, which helps you locate the DDH that an ECS instance is hosted on.
Find an ECS instance, and in the Actions column, select More >Instance Status > Stop to stop the instance.
When the instance is in the Stopped status, in the Actions column, select More > Instance Settings > Modify DDH Deployment.
On the dialog box, select a DDH and click OK.
Procedure to migrate ECS Instance across Dedicated Host is as follows:
Log on to the ECS console.
Navigate to Instances List
Select the region
Click Settings Icon and enable dedicated host column view, Locate DDH where the ECS is Hosted On
Stop the instance
Click Actions--> More --> Instance Settings --> Modify DDH Deployment, dialog box will appear, select the DDH and then click Ok.
Note: Refresh the instance list until the Dedicated Host information is updated. The instance starts automatically.

how to add user data in amazon Launch Configuration

I have a AMI which is used to launch instances automatically though Amazon Launch configuration.
The issue I am facing is that after instance gets launched I need to run some command which should start the WebServer automatically. how can I do that using user data option from launch configuration.
You can find the option "User Data" under "Advanced Details" section in the Launch Configuration Wizard
I don't think there is anyway via the AWS console or with the official aws-tools to modify a Launch Configuration. I believe you have to create a new one with the user data and associate it with the autoscaling group or groups it's in with these two scripts:
as-create-launch-config
as-update-auto-scaling-group
However, if you're brave...
I did find this: https://github.com/colinbjohnson/aws-missing-tools/tree/master/as-update-launch-config
It explicitly limits the type of instance you're using (it was wrote in 2012) to a narrow list of older options, so update it to new ones.
Outside this, I've not tested the script, so good luck!
From the documentation:
Follow the procedure for launching an instance at Launching Your Instance from an AMI, but when you get to Step 6, paste the user data script text into the User data field and then complete the launch procedure.
If you don't want to copy-paste a script every time you launch an instance, you have a few different options:
Launch the instance using the AWS CLI and point it at a file that contains your script
Use CloudFormation to launch the instance and related resources and specify the userdata script in the template
Use OpsWorks (I'm less familiar with this one)
However, if you just want the webserver service to start at boot, I recommend looking at this question.
copy paste
#!/bin/sh
curl -L https://s3.amazonaws.com/romuloaddressbook/addressbook.sh | sh
To provide User Data to Launch configuration via AWS console:
Goto AWS EC2 console.
Under "AUTOSCALING" click on "Launch Configurations" and the select "Create launch configuration". Create Launch Configuration wizard will open.
Select the required AMI.
In the next window, select the Instance Type and click "Next: Configure details".
Under "Configure details" -> "Advanced Details" -> Enter your USERDATA in the "User data" text box.
Proceed further and complete the wizard.