Troubleshooting the problem of inability to connect to ssh after the newly purchased Alibaba Cloud server ECS is created

Author: 13
GitHub: https://github.com/ZHENFENG13
Copyright statement: This article is an original article and may not be reproduced without permission.

Problem Description

Since the original server was about to expire, I bought a new ECS server while Alibaba Cloud was engaged in promotional activities. However, after initialization and startup, I could not connect through ssh. After executing the ssh command, the command line was stuck and no response. For any error message, it is stuck and no response, and no feedback information can be obtained. This is the first time I have encountered this kind of problem. I have bought Alibaba Cloud ECS many times, and this is the first time I have encountered this kind of inability to use ssh. connection problem.

Find out why

First, the following questions came to mind:

  • local network problem
  • ECS network problem
  • Whether the sshd service is open
  • Is the firewall turned on?
  • Is the port open

Then start to verify one by one:

The local network is all normal, this problem needless to say.

The problem verification of ECS is a bit troublesome, because it cannot be connected at all. You can only enter ECS through Alibaba Cloud's ECS remote connection to locate the problem. However, this remote connection is very difficult, so it is very annoying to use.

Check whether the ECS network is unobstructed

Get the Baidu homepage through the curl command:

curl 'http:www.baidu.com'

The result is as follows:

curl-baidu

The page code of Baidu can be obtained, indicating that the network is fine, but the operation interface is really ugly (helpless face.png).

Whether the sshd service is open

Execute the command to check the status of the sshd service:

service sshd status

The result is as follows:

sshd-status

The sshd service is running normally.

Is the firewall turned on?

Execute the command to check the firewall status:

service iptables status

The result is as follows:

iptables-status

The firewall is normally turned on and in working condition.

Next see if the firewall adds the set ssh port to the rules:

iptables -L -n | grep 端口号

iptables-sshd

You can see that the set port has been added to the iptables firewall rules.

Is the port open normally?

Use the netstat command to view the port status:

netstat -an |grep 端口号

The result is as follows:

net-port

The set port is normally monitored.

Instead of using the default ssh port of 22, I reset a port value to reduce the number of malicious scans of the sshd port by hackers.

Work order inquiry

After the above steps of network verification, firewall verification, and port verification are verified, and all are confirmed to be correct, the remote connection is made again. What makes people crash is that the console still has no response and cannot be connected.

There is no way, because there is no error message, I can only verify the above-mentioned problems again. After repeated confirmation, the crash is coming. After repeated verification many times, no problem is found. The service period settings and network are all normal. , the local network is also normal, and the command is correct, but still cannot connect to the server through the ssh command.

The whole process took some time, and after verifying it one by one, I came to a conclusion that there are no problems with the settings on both sides of the local and service period, so what is the problem? In the end, I really had no choice but to send an Alibaba Cloud work order to ask for a solution. After discussing the whole process with the other party, they told me that I needed to configure the security group, so I quickly went to the console to find the configuration page and set the port After the rule is added, it can be connected normally.

The page path is as follows:

Management console->ECS->Instance->Management->Security group for this instance->Configuration rules

The configuration page is as follows:

security group

Configure the port information correctly on this page.

Note: Since it is a private server, some information has been smeared.

Epilogue

The whole process is quite helpless. After all the links are confirmed to be correct, I still do not get the correct answer. I am very desperate, hahahaha. In fact, I have bought Alibaba Cloud servers many times. I was thinking, why did this problem occur only this time? I have never set up a security group in the past.

Well, now that it's solved, I won't complain, just sort it out and post it, hoping that other people will not be at a loss when they encounter this kind of problem.

First published on my personal blog , thank you for your support.

end

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325817212&siteId=291194637