Unable to connect to ssh on Google Cloud Platform: - google-cloud-platform

We are unable to connect to 'VM'via ssh instance on Google Cloud platform.
Here we are trying with the help of 'SSH' button available on the browser.
But following message is received:
We are unable to connect to the VM on the port 22.
We have tried to Stop and Start the VM but did not help.

You need to create a firewall rule that enables SSH access on port 22 for your VMs. It is better to make the 'Target' as a network tag instead of enabling SSH access for all of the machines on your VPC network.
You can use the CLI to perform this operation - using the default VPC
gcloud compute firewall-rules create <rule-name> --allow tcp:22 --network "default" --source-ranges "<source-range>"

Related

unable to SSH into a VM in GCP

I created a VM, assigned external IP to it in us-west1 region. Also i did assign a subnet to VM.
I created a firewall rule with options as direction-ingress, Source filters - 0.0.0.0/0, Protocols and ports - tcp:22, Targets - All Instances in the network.
Using gcloud command gcloud compute ssh --zone "xxxx" "xxxxxxxx" --project "xxxxxx" when i try to ssh into a VM, it is not allowing me to connect getting below error
ssh: connect to host xx.xx.xx.xx port 22: Operation timed out
Recommendation: To check for possible causes of SSH connectivity issues and get
recommendations, rerun the ssh command with the --troubleshoot option.
gcloud compute ssh xxxxxxx --project=xxxxxx --zone=xxxxxx --troubleshoot
Or, to investigate an IAP tunneling issue:
gcloud compute ssh xxxxxxx --project=xxxxxxx --zone=xxxxx --troubleshoot --tunnel-through-iap

vm instance failed to connect to backend with ssh

I created a VM instance in Google cloud and configured it properly with all the necessary software. then, I cloned its disk and created a new VM instance, utilizing the cloned disk; however, when I tried to connect ot the new instance via the SSH button, it does not succeed with a code 4003. Reason: failed to connect with backend. Connection via Cloud Identity-Aware Proxy Failed.
When an instance does not have a public IP address, SSH in a Browser needs to forward the SSH connection through IAP. The error "failed to connect to backend" indicates that the IAP proxy service was unable to open a TCP connection to the instance.
Ensure you have a firewall rule to allow Cloud Identity-Aware Proxy (IAP) to connect to port 22 on the instance.
Create a firewall rule
To allow IAP to connect to your VM instances, create a firewall rule that:
applies to all VM instances that you want to be accessible by using IAP. \
allows ingress traffic from the IP range 35.235.240.0/20. This range contains all IP addresses that IAP uses for TCP forwarding. \
allows connections to all ports that you want to be accessible by using IAP TCP forwarding, for example, port 22 for SSH and port 3389 for RDP.
To allow RDP and SSH access to all VM instances in your network, do the following:
Open the Firewall Rules page and click Create firewall rule
Configure the following settings:
Name: allow-ingress-from-iap
Direction of traffic: Ingress
Target: All instances in the network
Source filter: IP ranges
Source IP ranges: 35.235.240.0/20
Protocols and ports: Select TCP and enter 22,3389 to allow both RDP and SSH.
Click Create.
In Case you haven't enable your IAP you may refer on this link Enabling IAP for Compute Engine. You may check/browse also other related IAP guides on the left hand pane.

I want to create an in-house system. About GCE Firewall

I want to create an in-house system with GCE. I want to make HTTP and SSH connections only for people in the company, but not others. What should I do with a firewall?
By default, a Google Cloud project you create in Google Cloud Platform comes with the default firewall rules:
default-allow-icmp – allow from any source to all the network IP. ICMP protocol is mostly used to ping the target.
default-allow-internal – allow connectivity between instances on any port.
default-allow-rdp – allow RDP session to connect to Windows servers from any source.
default-allow-ssh – enable SSH session to connect to UNIX servers from any source.
You can create firewall rules in combination with network tags so the VM instances with this associated tag will be the target of your firewall rule. Moreover, you can combine multiple ports in a single rule.
Here below there is an example to allow HTTP and SSH connections via gcloud command in the Cloud Shell (alternatively, you can use the GCP graphical interface):
gcloud compute firewall-rules create allow-ssh-and-http --network default --allow tcp:22,80 --direction ingress --priority 1000 --target-tags ssh-and-http --source-ranges [CIDR_RANGE]
Afterwards, you have to add the network tag to the specific GCE instance.
gcloud compute instances add-tags [INSTANCE-NAME] --zone [ZONE] --tags ssh-and-http
If you wish to have a more granular access control, you have to set the proper permissions for each user or service account via IAM & Admin.

GCP open firewall only to cloud shell

Is there a way in GCP to explicitly allow firewall rule only from cloud shell. All the GCP demos and videos add the rule allow 22 to 0.0.0.0/0 to ssh to the instance from cloud shell.
However is there a way we could restrict the access only from cloud shell - either using cloud shell's IP range or service account ?
Google does not publish the public IP address range for Cloud Shell.
VPC firewall rules allow specifying the service account of the source and target. However, Cloud Shell does not use a service account. Cloud Shell uses the identity of the person logged into the Google Cloud Console. This means OAuth 2 User Credentials. User Credentials are not supported for VPC Firewall rules.
My recommendation is to use TCP forwarding and tunnel SSH through IAP (Identity Aware Proxy). Google makes this easy in the Cloud SDK CLI.
Open a Cloud Shell in the Google Cloud Console. Then run this command:
gcloud compute ssh NAME_OF_VM_INSTANCE --tunnel-through-iap
This also works for VM instances that do not have public IP addresses.
The Identity Aware Proxy CIDR netblock is 35.235.240.0/20. Create a VPC Firewall rule that allows SSH traffic from this block. This rule will prevent public SSH traffic and only allow authorized traffic thru Identity Aware Proxy.
Google has published the detailed info in this article - Configuring secure remote access for Compute Engine VMs
From the admin console, click Security then select Identity-Aware Proxy.
If you haven’t used Cloud IAP before, you’ll need to configure the oAuth screen:
Configure the consent screen to only allow internal users in your domain, and click Save.
Next, you need to define users who are allowed to use Cloud IAP to connect remotely. Add a user to the “IAP-secured Tunnel User” role on the resource you’d like to connect to.
Then, connect to the machine via the ssh button in the web UI or gcloud.
When using the web UI, notice the URL parameter useAdminProxy=true.
Tip: If you don’t have gcloud installed locally, you can also use Cloud Shell:
gcloud beta compute ssh {VM-NAME} --tunnel-through-iap
You should now be connected! You can verify that you don’t have internet connectivity by attempting to ping out. 8.8.8.8 (Google’s Honest DNS) is a good address to try this with.

problems connecting to AWS DocumentDB

I created a Cluster and an Instance of DocumentDB in amazon. When I try to connect to my Local SSH (MacOS) it displays the following message:
When I try for the MongoDB Compass Community:
mongodb://Mobify:<My-Password>#docdb-2019-04-07-23-28-45.cluster-cmffegva7sne.us-east-2.docdb.amazonaws.com:27017/?ssl=true&ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0
It loads many minutes and in the end it has this result:
After solving this problem, I would like to know if it is possible to connect a cluster of documentDB to an instance in another zone of availability ... I have my DocumentDB in Ohio and I have an EC2 in São Paulo ... is it possible?
Amazon DocumentDB clusters are deployed in a VPC to provide strong network isolation from the Internet. To connect to your cluster from outside of the VPC, please see the following: https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html
AWS document DB is hosted on a VPC (virtual private cloud) which has its own specific subnets and security groups; basically, anything that resides in a VPC is not publicly accessible.
Document DB is deployed in a VPC. In order to access it, you need to create an EC2 instance or AWS Could9.
Let's access it from the EC2 instance and access AWS document DB using SSH tunneling.
Create an EC2 instance (preferably ubuntu) of any configuration and select the same VPC in which your document DB cluster is hosted.
After the EC2 is completely initialized, start an SSH tunnel and bind the local port # 27017 with document DB cluster host # 27017.
ssh -i "<ec2-private-key>" -L 27017:docdb-2019-04-07-23-28-45.cluster-cmffegva7sne.us-east-2.docdb.amazonaws.com:27017 ubuntu#<ec2-host> -N
Now your localhost is tunneled to ec2 on port 27017. Connect from mongosh or mongo, enter your cluster password and you will be logged in and execute any queries.
mongosh --sslAllowInvalidHostnames --ssl --sslCAFile rds-combined-ca-bundle.pem --username Mobify --password
Note: SSL will be deprecated. Use tls, just replace SSL with tls in the above command.