EC2 Instance cannot connect to github using SSH - amazon-web-services

I'm trying to deploy a web with Laravel Forge and AWS. I created an EC2 instance using Laravel Forge control panel. I created a security group for this instance.
Outbund rules
Inound rules v1
Inbound rules v2
All SHH connections allowed are described in this Laravel Forge guide:
https://forge.laravel.com/docs/1.0/servers/providers.html
So, the problem is when I try to install the repository I get this error into EC2 instance.
SHH error
I also checked that my instance's SHH public key is registered in my github account

Your Outbound rules are permitting connections on port 80 (HTTP) and port 443 (HTTPS).
However, SSH uses port 22. This is causing the connection to fail.
You should add port 22 to the Outbound rules.
However, it is generally considered acceptable to Allow all outbound connections from an Amazon EC2 instance since you can 'trust' the software running on the instance. I would recommend allowing all outbound connections rather than restricting it to specific ports.

Related

Not able to ssh/http into EC2 instance

I am at my wits end with this, please help.
I am creating EC2 instances in my default public VPC, yet i am not able to ssh or http to my instance or webserver running into the machine. I checked the following
The SG has inbound SSH, HTTP and HTTPS allowed from 0.0.0.0/0 and assigned to my instance
the default VPC, has route tables with 0.0.0.0/0 pointed to IGW
the NACLs are configured to Allow all traffic. i also manually updated to allow only HHTP, HTTPS and SSH
the Key is use has been given the right permission by running chmod 400 filename
Despite all this not able to connect to the EC2 instance, AMI being Amazon Linux 2 AMI
When I try to ssh, i get a connection timeout error after a while, initially, i thought it was my office network but I am also getting the same from my home network with no firewalls in place
To allow an SSH connection, you will need:
An Amazon EC2 instance running Linux launched in a public subnet (defined as having a Route Table that directs 0.0.0.0/0 to an Internet Gateway)
A Security Group permitting Inbound access on port 22 (Outbound configuration is irrelevant)
Network ACLs left at their default settings of Allow All in both directions
A Public IP address associated with the instance
From your descriptions, I would say that the problem is probably with the Outbound NACLs. Return traffic from an SSH session goes back to the source port on the initiating server, which is not port 22. In general, only change the NACLs if you have a specific reason, such as creating a DMZ. I recommend you reset the NACL rules to Allow All traffic in both directions.

2 ec2 instance interacting with each other

I am new to aws and ec2 interaction with traffic flow.
I have one ec2 instance which I am using as a web server and other as an application server.
how can my two ec2 interact with each other maintaining all the security required?
Both the ec2 machines are on the ubuntu image.
I tried adding All ICMP - IPv4 with source 0.0.0.0/0. I feel it's not the correct way I want only my other instance to access it.
I also tried adding source as other instance security group but didn't work. I was not able to ping from one machine to other
The recommended security configuration would be:
Create a Security Group for the web server (Web-SG) that permits Inbound traffic for HTTP and HTTPS (ports 80, 443). Leave the Outbound configuration as the default "Allow All".
Create a Security Group for the app server (App-SG) that permits Inbound traffic from Web-SG on the desired ports. Leave the Outbound configuration as the default "Allow All".
That is, App-SG should specifically refer to Web-SG in the Inbound rules. This will permit traffic from Web-SG to enter App-SG.
You might want to add additional access so that you can manage the instances (eg SSH), or you can use AWS Systems Manager Session Manager to connect.
Do not use Ping to test access since that requires additional settings and only proves that Ping works. Instead, test the actual access on the desired ports (eg port 80).

AWS Session Manager can't connect unless opening SSH port

I'm trying to use AWS Systems Manager Session Manager to connect to my EC2 instances.
These are private EC2 instances, without public IP, sitting on a private subnet in a VPC with Internet access through a NAT Gateway.
Network ACLs are fully opened (both inbound and outbound), but there's no Security Group that allows SSH access into the instances.
I went through all the Session Manager prerequisites (SSM agent, Amazon Linux 2 AMI), however, when I try to connect to an instance through the AWS Console I get a red warning sign saying: "We weren’t able to connect to your instance. Common reasons for this include".
Then, if I add a Security Group to the instance that allows SSH access (inbound port 22) and wait a few seconds, repeat the same connection procedure and the red warning doesn't come up, and I can connect to the instance.
Even though I know these instances are safe (they don't have public IP and are located in a private subnet), opening the SSH port to them is not a requirement I would expect from Session Manager. In fact, the official documentation says that one of its benefits is: "No open inbound ports and no need to manage bastion hosts or SSH keys".
I searched for related posts but couldn't find anything specific. Any ideas what I might be missing?
Thanks!
Please make sure you are using Session Manager Console, not EC2 Console to establish the session.
From my own experience, I know that sometimes using EC2 Console option of "Connect" does not work at first.
However, if you go to AWS Systems Manager console, and then to Session Manager you will be able to Start session to your instance. This assumes that your SSM agent, role and internet connectivity are configured correctly. If yes, you should be able to see the SSM managed instances for which to start your ssh session.
Also Security Group should allow outbound connections. Inbound ssh are not needed if you setup up everything correctly.
Despite what all the documentation says, you need to enable HTTPS inbound and it'll work.
I had similar issue and what helped me was restarting SSM agent on a server. I've logged in with SSH and then run:
sudo systemctl restart amazon-ssm-agent
Session Manager Console immediately displayed EC2 instance as available.
Thanks for your response. I tried connecting using Session Manager Console instead of EC2 console and didn't work. Actually I get the red warning only the first time I try to connect without the SSH port opened. Then I assign a security group with inbound access to port 22 and can connect. Now, when I remove the security group and try connecting again, I don't get the red warning in the console but a blank screen, nothing happens and I can't get in.
That being said, I found that my EC2 instances didn't have any outbound port opened in the security groups. I opened the entire TCP port range for the output, without opening SSH inbound and could connect. Then I restricted the outbound port range a little bit: tried opening only the ephemeral range (reserved ports blocked) and that problem came up again.
My conclusion is that all the TCP port range has to be opened for the outbound. This is better than opening the SSH port 22 for inbound, but there's something I still don't fully understand. It is reasonable that outbound ports are needed in order to establish the connection and communicate with the instance, buy why reserved ports? Does the SSH server side use a reserved port for the backwards connection?
I was stuck with this similar issue. My Security Groups and NACLS had inbound and outbound ports open only to precise ports and IPs as needed in addition to ephemeral port range of 1024~65535 for all internal IPs.
Finally what worked was, opening up Port 443 outbound for all internet IPs. Even restricting 443 outbound to internal IP ranges did not work.
The easiest way to do this would be to create the 3 VPC interface endpoints that SSM requires in your VPC and associated subnets (Service Names: com.amazonaws.[REGION].ssm, com.amazonaws.[REGION].ssmmessages and com.amazonaws.[REGION].ec2messages).
Then, you can add an ingress and an egress rule for only port 443 that allows communication within the VPC.
This is more secure than opening up large swathes of the Internet to your private instances and faster since the traffic stays on AWS' own network and does not have to traverse NATs, or gateways.
Here are some helpful links to AWS documentation:
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-systems-manager-vpc-endpoints/
https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-prereqs.html
https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-privatelink.html
https://docs.aws.amazon.com/systems-manager/latest/userguide/setup-create-vpc.html
Another item that tripped me up: Make sure the security group for your VPC endpoints is open to all inbound connections on 443, and all outbound.
I had mine originally tied to the security group of the EC2 instances I was connecting to (e.g. SG1), and when I created another security group (e.g. SG2), I could not connect. The above reason was why... originally I set up my VPC Endpoints Security Group to reference SG1, instead of all inbound connections on 443.

Basic security group ports required to run AWS opsworks instances

I was trying to create some instances in aws opsworks stack. I am performing this on secured vpc. Which is not default one. That VPC have internet connection. However I have been instructed to restrict sources to required inbound ports to specific address only not to 0.0.0.0/0. Generally the ports we are using - ssh, http and https. ssh is ok to restrict to vpc subnet. but I have problem with http and httpd.
I have some queries-
1. What are the minimal inbound ports required to run opsworks properly and what will be the source? Hence we are not using 0.0.0.0/0
2. Since my cookbook stored in s3 which is accessible inside vpc. what will be the minimal port required.
3. I am not using Opsworks default security group. I am trying to use other security cookbook.
4. I have seen Opsworks are using some cookbooks from github.com. If I restrict then will it fail.
5. AWS said the following http and https source should be 0.0.0.0/0. link
6. When I am restricting ec2 instances are booting up but opsworks it is showing "setting-up" does not show any log messages.
Kindly advise what are the essential inbound ports to be opened and static source required to run in production vpc.
Regards
Biswajit Das
Chef client and solo in general require no inbound ports of any kind other than the usual ephemeral ports required for outbound TCP to function.

Why can't I access a port on my AWS instance, even though I have security group inbound rules that allow it?

I'm new to AWS so this is probably a "doh!" question.
I set up a CentOS 7 instance and assigned a elastic IP. I created a security group and created a custom TCP inbound rule that allows TCP traffic on port 8000 anywhere (0.0.0.0/0), an HTTP rule for port 80 also from 0.0.0.0/0, and SSH/port 22 rule from my laptop IP, and assigned the security group to my instance. iptables/6, firewalld, nor SELinux services are NOT running on the box.
I CAN SSH to the box with the elastic IP. I CAN access http://my_elastic_ip, but I can NOT access http://my_elastic_ip:8000/some.html
netstat shows the 8000 port in listening state, on all addresses.
What am I missing?
It turns out, these ports were blocked by my company's firewall. Enabling them resolved this issue.