How to establish SSH connection between two machines from different cloud providers? - amazon-web-services

I have one CentOS instance in AWS and another instance in Hybris Cloud.
The AWS instance is running a Jenkins Server and I want to install a slave for it in the Hybris Cloud Instance.
I have followed the steps to establish SSH connection between two machine but still can't get them to connect.
What am I missing? Is there any special SSH configuration for establishing connection between different cloud providers?

I cant speak for Hybris, but AWS has a security group for your EC2 instance. The security group for your AWS instance must allow port 22 from the IP address of your Hybris server (or a range of IP addresses). In addition, the host firewall on the EC2 Jenkins server must allow for this as well.
Likewise, the Hybris server must have the same ports opened up.
If you continue having issues after checking security groups and host firewalls, check the Network ACL in AWS. If you are in your default VPC and there have been no alterations, the Network ACL should allow for your use case. However if you are in a non-default VPC, whoever created it may have adjusted the Network ACL.

Related

AWS: can't connect to Amazon Linux EC2 instance

I'm working with AWS, I have an EC2 instance (Amazon Linux) but I can't connect to it, I've checked all VPC parameters and they are enabled as well as the instance, but when I try to connect it using EC2 Instance Connect I get this message:
I'm using the default user account, also I generated a key pair however I'm getting this other message:
Also, session manager can't connect.
So my question is: what settings do I need to update or check in order to connect to my EC2 instance?
Thanks a lot for your comments.
There are multiple ways to login to an Amazon EC2 instance.
SSH
Your screenshot shows that you are wanting to login via SSH, but it is saying that no Keypair was selected when the instance was launched. Therefore, this option is not available for you.
EC2 Instance Connect
If you ware wanting to login to the Amazon EC2 instance using EC2 Instance Connect and you are experiencing connectivity problems, then make sure that your Security Group permits Inbound access on port 22 from the IP address range of the EC2 Instance Connect service (not your own IP address).
This is because the EC2 Instance Connect client on your computer connects to AWS on port 443 (as a web connection), and then the traffic goes from the EC2 Instance Connect service to the EC2 instance as a normal SSH connection on port 22. Therefore, the Security Group needs to permit Inbound connections on port 22 from the IP address range of the EC2 Instance Connect service (or you can be lazy and just select 0.0.0.0/0, but that is a lower level of security).
You can find the IP address ranges for AWS services at: AWS IP address ranges - AWS General Reference
Please note that your EC2 instance must be in a public subnet and you must connect via a public IP address.
AWS Systems Manager Session Manager
The Session Manager connects in a totally different way, without using SSH. It requires an Agent to be installed on the EC2 instance (and it is there by default if you launched from an Amazon Linux AMI). This Agent then creates an Outbound connection to AWS, so it does not require any Inbound security rules (but it does require the default "Allow All" Outbound rule).
Session Manager has the additional benefit that it allows you to connect to EC2 instances that are in private subnets, as long as the EC2 instance can access the Internet via a NAT Gateway or if the VPC has a VPC endpoint for Systems Manager.

Elastic Beanstalk & EC2 Instance Connect: Can't connect

I created an Elastic Beanstalk environment from Visual Studio and need to login to service the underlying ec2 vm.
I don't have an credentials for the server, so I wanted to use EC2 Instance Connect.
When I click connect, I get an error message:
We were unable to connect to your instance. Make sure that your instance’s network settings are configured correctly for EC2 Instance Connect. For more information, see Task 1: Configure network access to an instance.
Following the link, I found the instructions:
Ensure that the security group associated with your instance allows inbound SSH traffic on port 22 from your IP address or from your network.
(Amazon EC2 console browser-based client) We recommend that your instance allows inbound SSH traffic from the recommended IP block published for the service. Use the EC2_INSTANCE_CONNECT filter for the service parameter to get the IP address ranges in the EC2 Instance Connect subset.
How do I connect to the Elastic Beanstalk underlying EC2 via EC2 Instance Connect?
What I've tried:
I created a new security group that contains my client IP address, but that didn't work. Which makes sense, as it's the EC2 Instance Connect app running in the Console making the SSH connection, not my local machine.
Also looked at the the ip ranges json file (https://ip-ranges.amazonaws.com/ip-ranges.json), but not sure what to do with that.
I misunderstood the Set up EC2 Instance Connect instructions. This support article had clearer instructions: https://aws.amazon.com/premiumsupport/knowledge-center/ec2-instance-connect-troubleshooting/
Browser-based SSH connections require that your instance's security group inbound rules allow EC2 Instance Connect access to SSH on TCP port 22.
The key was to find the IP for EC2 Instance Connect and then create
a security group to whitelist that ip address.
EC2 Instance Connect IP can be retrieved via PowerShell by using Get-AWSPublicIpAddressRange (or curl). For us-west-2:
> Get-AWSPublicIpAddressRange -Region us-west-2 -ServiceKey EC2_INSTANCE_CONNECT | select IpPrefix
IpPrefix
--------
18.237.140.160/29
Once I configured my Security Group to use that Source I could connect.
Generally better way then using EC2 Instance Connect is through SSM System Manager. It does not require opening any inbound ports. Instead you should add/modify your install role to allow SSM to work. What's more you can control access to your instance using regular IAM permissions, unlike for EC2 Instance Connect.
Connection through SSM is in the same menu in the AWS console as EC2 Instance Connect. Thus, once you setup your instance role, wait few minutes for the instance to register with SSM, and once this happens you should be able to use SSM System Manager to connect to your instance from the console.
Regarding EC2 Instance Connect IP range. I don't know which range published applies only to EC2 Instance Connect. You would have to filter it by region probably and then find one which works. In worse case scenario its try-and-see approach.

How to access AWS EC2 instance from web browser on Linux machine?

When I try to connect to my EC2 instance using web browser (Mozilla Firefox) using the third option in the connect (EC2 Instance Connect (browser-based SSH connection) ), I get the following error in the new pop-up window:
There was a problem setting up the instance connection
Log in failed. If this instance has just started up, try again in a minute or two.
Some things to check:
Make sure the instance was launched from Amazon Linux 2 or Ubuntu 16.04 or later
Check that the instance is in a public subnet (defined as having a Route Table that points to an Internet Gateway)
Open the Security Group for SSH (port 22) either for the whole Internet (0.0.0.0/0) (which is a very poor choice for security) or from the IP address ranges for EC2 Instance Connect (See: AWS IP Address Ranges - AWS General Reference)
EC2 Instance Connect in your browser establishes a web connection to the AWS service. Then, the SSH connection is established from the AWS Service to the Amazon EC2 instance. This is why the security group needs to allow incoming connections from the IP address range associated with the EC2 Instance Connect Service (not your own IP address).
Alternative ways to connect are:
Run an SSH client on your computer, or
Use AWS Systems Manager Session Manager (which connects via an Agent running on the computer, so it's not 'real' SSH)

How to ping from EC2 instance to on-premises Windows Server using AWS VPN?

By following the link below, I have successfully setup Windows Server 2012 R2 as a Customer Gateway.
https://docs.aws.amazon.com/vpc/latest/adminguide/customer-gateway-windows-2012.html
I am able to ping the EC2 instance from my on-premises Windows Server. However, I want to do the vice-versa i.e., to ping the on-premises Windows Server IP from EC2 inside instance (RDP). May I know how to do this please?
I logged into EC2 instance through RDP. Pinged my on-premises Windows Server from there (192.168.X.X) but it returned 'Request timed out'.
Why do I need this?
I am doing all these because I want to migrate & replicate data automatically from my on-premises SQL Server to DB in Cloud. I decided to use AWS Database Migration Service (DMS). In order to set source endpoint (on-premises SQL Server), I need to let AWS communicate to my on-premises network through private IP. DMS should recognize 192.168.X.X\MSSQLServer.
Check outbound filters on your security group (but by default should allow everything).
Check your NACL to ensure it allows proper inbound/outbound traffic since it is stateless.
Check your Windows firewall in your Windows Server to ensure it will allow inbound ICMP.

Giving Jenkins access to AWS instance behind a VPN

I need to trigger a Jenkins build that will access a Chef server installed on an EC2 instance which is behind a VPN.
Potentially the security group could be relaxed to allow the Jenkins server's IP, but I hope to avoid that.
Is there a way to connect Jenkins to a VPN while executing a build?
A Google search of this yielded this plugin on github but in its Jenkins page there's no real information nor is it downloadable.
One way to do this is to have a well-secured bastion server acting as an interface into the VPC and having access to tunnel (with SSH, VPN or something else) only the kind of requests you want to allow in.
You should create a NAT gateway in the account where Jenkins is installed. NAT Gateway will have Elastic IP and all the resources in this VPC (including Jenkins) will reach to Internet using this EIP. Then you configure your target security group to allow connections from this Elastic IP.
create OpenVPN ec2 instance from aws marketplace and create ec2 instance for ur jenkin and add the security group of ur openvpn instance to jenkin instance .. so that once u connect your openvpn then only u access ur jenkin instance...
Note: Openvpn instance is not free of cost