When you encounter a "connection refused" error while remotely connecting to a Linux instance, it typically indicates that the remote service (e.g., SSH) is not running, the port is blocked, or the instance is unreachable. Here’s how to troubleshoot and resolve the issue:
sshd service is active:sudo systemctl status sshd
If it’s not running, start it:sudo systemctl start sshd
Enable it to start on boot:sudo systemctl enable sshd
sudo ufw allow 22 # If using UFW
Or check iptables:sudo iptables -L -n
ping <instance_ip>
/etc/ssh/sshd_config for misconfigurations (e.g., wrong port or ListenAddress).sshd after changes:sudo systemctl restart sshd
sudo netstat -tuln | grep 22
/etc/ssh/sshd_config and update the firewall rules.If you modified /etc/ssh/sshd_config to change the SSH port to 2222 but forgot to update the firewall:
sudo ufw allow 2222
2222.sshd:sudo systemctl restart sshd
ssh -p 2222 user@instance_ip
For Tencent Cloud, you can also use VNC Console in the console to access the instance directly if SSH is unavailable.