gcloud compute scp - Connection Failed (Sometimes with 4010 Error Code) - google-cloud-platform

"Connection Failed
You cannot connect to the VM instance because of an unexpected error. Wait a few moments and then try again."
When I tried to copy file from one virtual machine to another using scp, ssh client loses connection. Command that I run is the following:
gcloud compute scp --recurse file_name account#instance_name:~/folder --zone zone_name --project project_name
What can be the reason of it?

Make sure that you have opened port 22, which is the port that allows communication with SSH. If you are not sure, you can create a rule by going to VPC -> Firewall Rules -> port 22.
Here is an article that can help with allowing SSH connection
This other article can help you troubleshooting SSH
You can also run the following command to check which ports you have open netstat -tuplen, make sure you have port 22 listening.

Related

No Ingress firewall rule allowing SSH found

No ingress firewall rule allowing SSH found.
If the project uses the default ingress firewall rule for SSH, connections to all VMs are allowed on TCP port 22. If the VPC network that the VM’s ## Heading ##network interface is in has a custom firewall rule, make sure that the custom firewall rule allows ingress traffic on the VM’s SSH TCP port (usually, this is TCP port 22).
To investigate further, enable the VM's serial console. Then connect through the VM’s serial port, check the SSH server's listen port, and then compare the listen port number with the VM's firewall rules. The port numbers must match.
How to remove the network error, while initiating VM via SSH
This error can occur for several reasons. The following are some of the most common causes of the errors :
The VM is booting up and sshd is not running yet.
The firewall rule allowing SSH is missing or misconfigured.
sshd is running on a custom port.
Your custom SSH firewall rule doesn't allow traffic from Google
services.
The SSH connection failed after you upgraded the VM's kernel.
The sshd daemon isn't running or isn't configured properly.
The VM isn't booting and you can't connect using SSH or the serial
console.
The VM is booting in maintenance mode.
Please check for the above mentioned errors in serial port and refer to this documentation to resolve the issue.
You can also try these steps :
Stop the VM instance.
Click 'Edit' to edit the instance.
Under ‘Metadata' section, add 'startup-script' key, with value:
#! /bin/bash
sudo ufw allow 22
Click 'Save'
Start the instance again, and SSH into it

Unable access Jupyter lab from Google Deep Learning VM

I am trying to open Jupyter Lab after installing Google Deep learning VM.
This code i am running in SSH terminal in browser:
export PROJECT_ID="name"
export ZONE="us-west1-b"
export INSTANCE_NAME="tensorflow-1-vm"
gcloud compute ssh --project $PROJECT_ID --zone $ZONE \
$INSTANCE_NAME -- -L 8080:localhost:8080
I always get same mistake and cannot access to http://localhost:8080/ :
bind: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 8080
Could not request local forwarding.
Could you please tell me what am i doing wrong? Thank you!
Make sure your instance has firewall rules configure to allow http/https egress protocol along and the instance have a public IP.
Check this out https://cloud.google.com/ai-platform/notebooks/docs/ssh-access

GCP vm firewall block all incoming port but 80. How SSH?

I ssh to GCP Centos vm instance by port 22 but I run firewall-cmd script to block all incoming port except 80. Now I cannot ssh to connect my vm instance due to port 22 is blocked. Is there any solution to allow ssh again because I can not do anything. Please help.
Sincerely
Bom
You can solve this by creating a startup-script with the firewall-cmd commands you need to have the port 22 opened and then apply it to your instance.

Why can't my ubuntu ansible ping my aws machine?

I have /etc/ansible/hosts locally as:
[example]
172.31.20.nnn # nnn not shown, is 1-255
I created an aws ubuntu instance and a .pem file in my local directory I can log in ok
ubuntu#ip-172-31-20-nnn:~$ whoami
ubuntu
ubuntu#ip-172-31-20-nnn:~$
However when I try
ansible example -m ping -u ubuntu
I get
172.31.20.nnn | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host 172.31.20.nnn port 22: Connection timed out",
"unreachable": true
}
nnn is a number in all cases, just not shown here
Stuck on adding ping - i see the following showing 22. What should I do ?
I see this, but i don't see ping in the dropdown.
should i be deleting the existing 22 rule that was already there?
Tried that. No.
Your EC2 security group is blocking the ICMP requests. You just need to open the PING service on it

SSH connection issue to AWS EC2 instance

I am using cygwin which has ssh configured.
I am using a windows machine
Path to keypair file : C:\cygwin64\home\suhelkhan.ssh\kworld_kp1.pem
The EC2 instance is Red Hat Enterprise Linux (RHEL) 6
The EC2 is correctly mapped to the keypair
The security group associated with this EC2 instances allows for SSH
connection.
I am using the following command to connect
suhelkhan#DTDVD0003009PR ~/.ssh
$ ssh -vvv "kworld_kp1.pem" ec2-user#ec2-52-63-yyy-zz.ap-southeast-2.compute.amazonaws.com
output:
OpenSSH_7.3p1, OpenSSL 1.0.2h 3 May 2016
debug2: resolving "kworld_kp1.pem" port 22
ssh: Could not resolve hostname kworld_kp1.pem: Name or service not known
Checking with telnet gives the following:
suhelkhan#DTDVD0003009PR ~/.ssh
$ telnet 52.63.141.40
Trying 52.63.141.40...
telnet: Unable to connect to remote host: Connection refused
The Telnet cmd gives out the following:
suhelkhan#DTDVD0003009PR ~/.ssh
$ telnet HOST 22
Can't lookup hostname HOST
I just redid the whole thing (New instance with appropriate security group, Proper Key-Pair match up and new cygwin installation [http://thecoatlessprofessor.com/programming/installing-amazon-web-services-command-line-interface-aws-cli-for-windows-os-x-and-linux-2/ ]) .Also added my Public IP to the inbound tab of the security group i am using.. all works.. thanks for the all the help