DEV Community

Tonny Kirwa
Tonny Kirwa

Posted on

SSH: "Connection refused" Fix - Ubuntu Server

The "Connection refused" error typically indicates that the SSH service is not running on the specified host, or a firewall is blocking the connection.

Error below

root@00bc17d6e6f8:/# ssh -v ubuntu@100.24.238.153
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014

debug1: Reading configuration data
/etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying
options for * debug1: Connecting to 100.24.238.153 [100.24.238.153]
port 22. debug1: connect to address 100.24.238.153 port 22:
Connection refused ssh: connect to host 100.24.238.153 port 22:
Connection refused root@00bc17d6e6f8:/#

Here are a few steps to troubleshoot the issue:

  1. Check SSH Service: Ensure that the SSH service is running on the remote server. If you have access to the server, you can check and restart the SSH service using the following commands:
   sudo service ssh status
   sudo service ssh restart
Enter fullscreen mode Exit fullscreen mode
  1. Firewall Configuration:
    Make sure that the firewall on the remote server is not blocking incoming connections on port 22 (the default SSH port). You can temporarily disable the firewall or allow SSH traffic through it.

  2. Security Group / Network ACLs (for AWS):
    If you are using Amazon Web Services (AWS), check the security group and network ACL settings for the instance. Ensure that incoming traffic on port 22 is allowed.

  3. Check if SSH is Listening:
    On the remote server, check if SSH is listening on the specified port (22 by default). You can use the following command:

   sudo netstat -tulpn | grep 22
Enter fullscreen mode Exit fullscreen mode

This should show an entry for the SSH daemon (sshd) listening on port 22.

  1. Restart SSH Service on the Remote Server: If the SSH service is running, try restarting it on the remote server:
   sudo service ssh restart
Enter fullscreen mode Exit fullscreen mode
  1. Check Server Logs:
    Examine the logs on the remote server for any SSH-related issues. The location of the logs may vary depending on your server's operating system. Common locations include /var/log/auth.log, /var/log/secure, or /var/log/messages.

  2. Confirm IP Address:
    Double-check that the IP address (100.24.238.153 in this case) is correct and corresponds to the intended server.

After performing these steps, try connecting again:

ssh -v ubuntu@100.24.238.153
Enter fullscreen mode Exit fullscreen mode

The -v option provides verbose output and might give more details about the connection issue. If the problem persists, inspect the logs and error messages for further troubleshooting.

Top comments (0)