How to Fix the SSH “Connection Refused” Error (With 5 Troubleshooting Methods)

An SSH “Connection Refused” error occurs when an attempt to connect to a remote server is denied, leading to significant security vulnerabilities. Here’s what can cause this error, troubleshooting tips, security best practices and more on how SSH works.

Written by Metin Kortak
network error icon on laptop representing ssh connection refused
Image: Shutterstock / Built In
Brand Studio Logo
UPDATED BY
Matthew Urwin | Mar 26, 2025

Secure Shell (SSH) is a protocol commonly used by system administrators to manage servers, configure network systems and perform remote operations efficiently. It encrypts data sent over a network, ensuring that sensitive information such as login credentials remains secure from eavesdroppers. 

Unfortunately, using this protocol can result in a “Connection Refused” error. The SSH “Connection Refused” error occurs when your attempt to connect to a remote server is denied, usually indicating a problem on the server side that prevents you from accessing the system. 

Before going into more detail on how SSH works, let’s look at some causes of the “Connection Refused” error and ways to troubleshoot it. 

Ways to Fix an “SSH Connection Refused” Error Explained

  • Install the SSH server software
  • Enter the correct login credentials
  • Ensure the SSH port is open
  • Adjust firewall rules to allow SSH traffic
  • Restart the SSH service if it’s down

 

What Causes an SSH “Connection Refused” Error? 

The SSH “Connection Refused” error is a common issue that occurs when you try to connect to a remote server but fail to establish a successful connection. This error can be caused by a number of factors:

1. Incorrect Login Credentials 

One of the most frequent causes of the “Connection Refused” error is the use of invalid credentials. This includes entering the wrong username or password, or using a mismatched SSH key pair. Ensuring you have the correct credentials is essential for gaining access to the server.

2. Closed SSH Port

By default, SSH operates over port 22. If this port is closed or blocked by another application, the SSH client will be unable to connect to the server. This can occur if the server is configured to listen on a different port or if a firewall rule is blocking the default SSH port.

3. Firewall Restrictions 

Firewalls are used to protect networks from unauthorized access, but they can also inadvertently block legitimate SSH traffic. If a firewall rule is preventing SSH connections, you will see a “Connection Refused” error. Make sure your firewall settings allow SSH traffic through the appropriate port.

4. Inactive SSH Service

The SSH service must run on the server to accept connections. Any connection attempts will be refused if the service is inactive or crashed. Checking the status of the SSH service and restarting it if necessary can resolve this issue.

5. Absence of SSH Server Software 

If the SSH server software is not installed on the remote machine, the server will be unable to accept SSH connections. Installing and properly configuring the SSH server software is required to enable remote access.

6. Incorrect IP Address or Hostname 

Using the wrong IP address or hostname can also result in a “Connection Refused” error, as the client cannot reach the intended server. Verifying that you use the correct network address can help resolve connection issues.

7. Network Issues 

Network-related problems, such as a weak or unstable internet connection, can disrupt the SSH connection process. Ensuring a stable and reliable network connection is crucial for successful SSH communication.

More on CybersecurityUnderstanding ISO 42001: A Framework for Responsible AI

 

A tutorial on how to resolve the SSH “Connection Refused” Error. | Video: Kinsta

How to Troubleshoot an SSH “Connection Refused” Error

Addressing the SSH “Connection Refused” error requires implementing practical solutions. Here is step-by-step guidance to resolve the key issues leading to this error.

1. Server Not Installed

A “Connection Refused” error may mean the SSH server software is not installed on the remote server. Here’s how to fix it: 

  1. Verify installation: Run ssh localhost on the server. If you see "command not found," install the OpenSSH server using: sudo apt-get install openssh-server
     
  2. Start service: Ensure the service is running with: sudo systemctl start ssh

2. Credentials Are Wrong

Incorrect login credentials such as a username, password or SSH keys are being used.

  1. Verify credentials: Ensure the correct username and password are used. For SSH keys, ensure your client’s private key matches the server’s public key. 
  2. Connect with a key using: ssh -i /path/to/private/key user@hostname

3. SSH Port Is Closed

The default SSH port (22) is closed or used by another service.

  • Check Port Status: Run `netstat -tuln

4. Firewall Settings Are Preventing an SSH Connection

Firewall rules are blocking SSH traffic to the server.

  • Allow SSH: On Linux with ufw, allow SSH traffic using: sudo ufw allow ssh 
  • Allow Non-default Port: If using a different port, allow it with: sudo ufw allow 2222

5. SSH Service Is Down

The SSH service is not running on the server.

  1. Check Service Status: Verify the service status with: sudo systemctl status ssh 
  2. Start Service: If inactive, start the service: sudo systemctl start ssh 
  3. Enable on Boot: sudo systemctl enable ssh

Fixing the SSH “Connection Refused” error is essential for maintaining secure and reliable access to your servers. By identifying the underlying cause of this error and applying the appropriate solution, you can prevent disruptions and ensure your systems remain accessible and secure. Regularly monitor and maintain your SSH configurations to avoid future issues and keep your network operations running smoothly.

More on CybersecurityHow to Securely Transfer Files Using SFTP

 

Best Practices for SSH Security 

Developing robust SSH security measures can help teams avoid and address any major repercussions of a “Connection Refused” error. Here are some tips to keep in mind:   

  • Use SSH keys: Transition from passwords to SSH keys, which allow access to remove servers via private-public key pairs. 
  • Create strong passwords: If keeping passwords, strengthen them by adding numbers, special characters and upper and lower case letters. 
  • Set authorized access: Allow only authorized users to access an SSH protocol, and keep a list of users that’s regularly updated. 
  • Switch to a non-standard port: Change the default SSH port to a non-standard port, which can limit threats like automated brute force attacks and scanning attempts.
  • Disable root login: Removing root login access reduces the chances of a bad actor gaining control over an entire system.  
  • Establish security layers: Additional methods like two-factor authentication and firewalls can further fortify SSH security. 
  • Monitor SSH logs: Check SSH logs to detect any unusual activity, and make sure SSH software is updated regularly to introduce the latest patches and features.  

 

How Does SSH Work?

SSH works on top of the Transmission Control Protocol (TCP)/Internet Protocol (IP) suite, which is the foundation of the internet. TCP and IP are two protocols that work together to send data across networks:

  • IP: Protocol that acts like a mailing address, telling data packets where to go.
  • TCP: Protocol that’s responsible for safely transporting and delivering data packets. It’s like an apartment number, guiding packets to the correct location on a device.

On top of TCP and IP, other protocols like SSH, HTTP, FTP and SMTP make the data understandable and usable by applications. In particular, SSH helps securely manage and access devices over the network.

SSH operates on a client-server model where the client initiates the connection to the server. The connection is authenticated using credentials, such as a username and password or cryptographic keys. Once authenticated, SSH provides a secure channel over an unsecured network, enabling users to execute commands and transfer files securely. 

The protocol also supports tunneling or port forwarding, enabling data packets to travel across networks they otherwise couldn’t access. SSH maintains confidentiality and integrity by utilizing encryption, making it a critical component of modern network security.

Frequently Asked Questions

The SSH “Connection Refused” error can be caused by various issues such as incorrect login credentials, a closed SSH port, firewall restrictions, an inactive SSH service, or the absence of the SSH server software on the remote machine. Common reasons for this error include:

  • Server Not Installed: SSH server software might not be installed on the server.
  • Incorrect Credentials: Wrong usernames, passwords, or keys can prevent connection.
  • Closed SSH Port: The default SSH port (22) might be closed or blocked.
  • Firewall Restrictions: Firewall settings may block SSH traffic.
  • SSH Service Down: The SSH service might not be running on the server.

Addressing the SSH “Connection Refused” error is crucial for maintaining uninterrupted access to your server. This error could signify security vulnerabilities or configuration issues that might impact other users or services relying on SSH access. Resolving this error ensures your server remains secure, accessible and operational. Ignoring these issues could lead to increased downtime, security risks and potential data breaches.

To troubleshoot SSH connectivity issues:

  1. Verify that the SSH service is running on the server by using the systemctl status ssh command.
  2. Ensure your login credentials, such as the username and password or SSH keys, are correct.
  3. Check that the correct port, usually port 22, is open using the netstat -tuln ' grep :22 command. 
  4. Review the firewall settings to ensure SSH traffic is allowed, adjusting rules if necessary.
  5. Utilize diagnostic tools like ping to check network connectivity and ssh -v for verbose output to help pinpoint specific problems during the connection process.
Explore Job Matches.