Different ssh port than 22 on ec2 - amazon-web-services

I recently changed port field with custom port sshd_config file on amazon ec2.
However, it doesn't respond to ssh -p1234 user#domain.com because of security groups.
I have my ssh port (22) open on security group but I need to make it 1234 but on aws console, when I changed ssh source to 0.0.0.0/1234 it says unable to find group.
So, how do I set security group right ?

You appear to have confused the port with the CIDR address.
The CIDR annotation describes the range of addresses which are permitted to establish connections on a port - if you want anyone to be able to access the port from any address, use 0.0.0.0/0.
You then specify the port separately, which in your case is 1234.

Please note that changing your ssh port is not considered as a best practice. Network scanners will find your 'hidden' ssh port in no time. It is actually worse than having ssh on 22 since it provides you with false sense of security.
Consider restricting the actual scope of this service to your home / office IP addresses (as instructed by AWS Trusted Advisor)
You can even utilize Dome9 to have this port normally closed and only opened on demand.
(disclaimer: I'm a proud Dome9'er)

Related

Remote desktop connection to ec2 instance

I have created a new free-tier windows 2019 EC2 instance in my default VPC, the new EC2 has a public IP, and the security group allows the traffic from anywhere and the RDP protocol is already configured to be ready on port 3389.
I have spent two days now with no luck connecting to this instance from windows remote desktop.
I have tried to ping the ec2 from my machine but no luck.
telnet from my machine to the ec2 working perfectly.
I have disabled the windows firewall.
remote desktop sometimes asks me to enter the password and sometimes doesn't ask at all.
**** when I changed my wifi network, I do the remote desktop connection and I can access the ec2 instance.
Any help in this.
I had the same issue as you have. In my case, The internet service provider blocked the SSH connection(PORT). though our security group allows to all we can't connect our instance.
Take this to them and get it fixed:).
I have a windows machine in EC2 which works, with the security groups set up as follows:
Inbound RDP, TCP port 3389 from 0.0.0.0/0
Inbound All ICMP v4 from 0.0.0.0/0 <- This is necessary to ping the machine
Outbound All traffic, All protocols, all ports to 0.0.0.0/0
Outbound ALL traffic, All protocols, all ports to ::/0
A few more hints:
If you restarted the machine and haven't attached an elastic IP, the public IP address will have changed
You can try telnetting to the RDP port 3389
Run the reachability analyzer tool in the VPC management console
You can try connecting via a different computer or a different connection, e.g. a personal hotspot to rule out firewall issues on your side
Update:
RDP is a quite ressource-intensive protocol compared to e.g. ssh or telnet. You haven't specified if you are trying this from a home or corporate network. Could the quality of your internet connection be a problem? Comparing to e.g. a public or private hotspot might help.
Last but not least, you say it worked when you "changed your wifi network" - I'm not quite sure what to make of that statement. Did you change the configuration? Did you change TO your wifi from a wired network?
If you are in a high-density area, Wifi networks can strangle each other. If you always were wireless, try wired. If your wireless works better than your wired, check the cables for kinks and tears.
Colleagues of mine once spent an hour trying to find out why a mainboard would always go into flash mode, until I suggested unplugging the keyboard - it was a stuck F10 key. Bottom line: try to think of the factors you've so far overlooked.
You probably need to setup your inbound rules on the security group.
Go to Instances and find the value for the column: Security Group Name
Then under Network and Security go to Security groups.
Click on the Security group ID that has the matching Security Group Name you looked up.
In the inbound rules you need to make sure you add yours and modify it until it looks like this:
Type: RDP Protocol:
TCP Port: 3389
Source: 0.0.0.0/0
Description: open to the world to test only
Better would be to use a source that you know you are coming from, but you'll need to change it if your IP changes.
https://www.whatismyip.com/
if your IP is 17.18.19.20,
then enter 17.18.19.20/32

Why does it matter if my EC2 instance is publicly available?

I have three allowable inbound requests on my Linux EC2 instance.
Type Protocol Port Range Source
SSH TCP 22 [my ip address]
Custom TCP Rule TCP 8787 0.0.0.0/0
Custom TCP Rule TCP 3838 0.0.0.0/0
The first is my IP address and the other two are for RStudio Server. My understanding is that, even though it is set for RStudio Server, anyone can make inbound requests since the source is open.
Nobody can access my EC2 instance without the private key file, which is safe and secure.
Given that, why does it matter whether my EC2 instance is private?
The private key file is to authenticate you for an ssh session (or to retrieve the password for a Windows EC2 instance).
If a port is accessible to the public, and an application is listening on that port someone may be able to exploit a vulnerability in that application and compromise your EC2 instance.
Even if only the ssh port is open to public but no one other than you has the private key, it's possible (theoretically) for someone to brute force ssh (although not practically possible).

EC2 is not responding for ssh connection

Another bad day. I have all the configuration for my ec2 instance.
Till yesterday I was able to connect it via ssh on mac. but know why it's not getting connect now.
Configuration is as below:
Security Group:-
I'm using below steps as usual and I'm same directory where mypleaks-inst.pem kept.
My guess: Your security group that was applied was "launch-wizard-2" which by default sets exlusion rules. You need to associate that EC2 instance with one of the two security groups listed in your second screen shot to allow TCP connections on port 22 from inbound ip range. OR you could modify launch-wizard-2 to incorporate the relevant rules to allow for ssh connection.
if you're sure nothing was changed on AWS side then perhaps your SSH service is down temporarily or permanently (the server was overloaded? You can do it with ease with T2.small).
Check NACL and routing, otherwise.

Why can't i telnet my aws instance?

Created an AWS AMI instance.
I can telnet from the instance itself
telnet [Pv4 Public IP] 9200
But not from my pc.
This is my security group
What am I doing wrong?
You can check your Network ACL configurations.
It looks like there is some other firewall in between your PC and server which is blocking you on 9200.
If you can access port 80 via telnet or you're able to SSH in it's likely you have a network ACL in place. If you can not access port 80 via telnet but you can via a browser it's like a local config - maybe AV or a firewall.
EC2 instances use security groups for their firewall
Another test to narrow down the the issue would to see if you could telnet from another instances in the same subenet in the same AZ. Being in the same subnet you should not be affected by a network ACL.
You can have a look at this telnet-to a cloud instance from outside
The solution to problem was "Open the services and make the telnet manual and right click on it and chose start"
As well make sure that the instance is residing in a public VPC
Based on what you've described, there isn't really much else to work with. Your ability to telnet the public IP from the instance implies the server is listening on the external interface and your security group is already set to have the port open to all incoming connections.
Aside from the trivial overlooking of not actually having the instance under the listed security group, the only possibility I can think of now is an active firewall on the instance. In the case of iptables or ufw (which is an interface to iptables), it's trivial to verify whether they are indeed getting in the way:
// List iptables access rules
sudo iptables -L -v
// List access rules via ufw
sudo ufw status
You said: "This is my SG", but...which way? Inbound or outbound?
It can simply be that your host can't reply to your PC.
Try to add a rule which adds outbound TCP ranging from ports 32768 to 65535 (ephemeral ports), so that the telnet server response packets can travel back to your PC.
Otherwise, like the others said, look at one level up, VPC-level (network ACL).
You might have your acceptor process running on 127.0.0.1:9000 which means only local clients can connect. This is not related to your Security Group which could be wide open.
Run lsof -i:9000 if on unix.
If you see something like this under NAME then host IP used to start your acceptor will needs to change from 127.0.0.1 to 0.0.0.0 (and secure via SG/FW).
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 2777 ubuntu 148u IPv6 26856 0t0 TCP localhost:afs3-callback (LISTEN)
A Telnet service is not installed by default on an Amazon Linux AMI.
If you wish to use it, you will need to install it yourself, eg: Install and Setup Telnet on EC2 Amazon Linux or CentOS.
However, these days it is recommended to use ssh instead of telnet because it is more secure. See: Telnet on wikipedia
Just a thought, check firewall of your PC.
Need to ensure your SSH key you generated via IAM and attached to the EC2 at launch is added to the login:
ssh-add -K <yourkeyname>.pem
ssh ubuntu#<yourdns or ip>.com == or == ssh ec2-user#<yourdns or ip>

How to view website launched in Amazon EC2 instance?

I have followed the steps provided by Amazon EC2. I have installed a wordpress website in the EC2 Instance.
My public DNS is given as ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com/
and Public IP is also given as xx-xxx-xx-xxx.
How to view the website from any other machine?
Note:
EC2 Instance is created and running now.
I can view it in the localhost as well as public DNS in the EC2 instance using RDP. (http://ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com/)
If you can see the web site from the EC2 instance, but not from other machines, there is probably one of the following things wrong:
The DNS entry is not available or is wrong. Since you can RDP using that entry, this can't be the cause.
Access to the correct port is being blocked by the security group or firewall. Since the instructions you referenced specifically say to make sure that both port 80 (HTTP) and 3389 (RDP) are open, and you know that is true from port 3389, this isn't likely, but is possible. Make sure that there are security group rules for both port numbers that look the same.
The Windows server itself is refusing to allow outside access to port 80 on that address. This is unlikely, but not impossible, and the instructions specify that you should "disable Internet Explorer Enhanced Security Configuration", and at the end cover "Making Your WordPress Site Public". Make sure that the web server isn't configured to only respond to requests from localhost (127.0.0.1) and that there are no Windows firewall rules blocking port 80.
I think that the likeliest problem is number 2, above. Perhaps you forgot to open port 80 in the security group, or typed a different port number or a different address range to open it to.