Jannah Theme License is not validated, Go to the theme options page to validate the license, You need a single license for each domain name.
How To

SSH Connection Refused Error On Linux? How To Fix

SSH is a remote access and management protocol for a network system. You may have encountered the “connection refused” error when connecting to a remote machine over SSH. This issue might be annoying if you are a system administrator and need to undertake urgent work on the remote system. Let’s look at various potential reasons for the SSH “connection refused” error and how to resolve it.

SSH Connection Refused Error On Linux? How To Fix

Check If An SSH Server Is Installed

The remote machine may not be running an SSH server, a probable source of the “connection refused” error. The machine will not accept inbound SSH connections without the SSH server, and you cannot access it remotely. As a result, the first step in debugging the error is to check if an SSH server is installed on the remote machine. To verify the SSH server installation, use the following command.

On the Debian-based distributions.

dpkg --list | grep ssh

On the RHEL-based distributions.

yum list installed | grep ssh

Next, on the openSUSE.

zypper search -i | grep ssh

On the Arch-based distributions.

pacman -Q | grep ssh

Well, if the SSH server is installed on the remote machine, it will be listed in the output. Alternatively, you must install the OpenSSH server on the remote machine you wish to access through SSH. OpenSSH is an open source version of the SSH tools for remotely accessing and controlling systems.

Use the following commands to install the OpenSSH server.

On Debian-based distributions.

sudo apt install openssh-server

On RHEL-based distributions.

sudo yum install openssh-server

Next, on openSUSE.

sudo zypper install openssh

On Arch-based distributions.

pacman -S openssh

Check SSH Service Status

The SSH service on the remote machine may be deactivated or not running, which is another explanation for the “connection refused” error. The status of the SSH server should be checked once you have confirmed that it is installed.

sudo systemctl status sshd

The output will show the service as active if it is up and running (running). Otherwise, you would see something like inactive (dead).

SSH Connection Refused

If the SSH server isn’t running, use the following command to start it.

sudo systemctl start sshd

You may also set the service to start automatically when the computer boots.

sudo systemctl enable sshd

Check SSH Port

The SSH server operates on port 22 by default. The default port may be changed, though. As a result, if you receive the SSH “connection refused” error, it might be because you are trying to connect to the SSH server on port 22 while it is running on a different port. Well, to find the port the SSH server is listening on, run the netstat command with grep.

sudo netstat -plntu | grep ssh

SSH Connection Refused

You may also use the following command to find the SSH port in the sshd_config file.

grep port /etc/ssh/sshd_config

Try connecting to the remote system using that particular SSH port after identifying the proper one.

Check System Firewall

Most connectivity issues are caused by your machine’s firewall blocking certain ports or services. Assuming the SSH server is installed and running on the remote machine, the next step is to check your firewall. Use the following commands to temporarily deactivate the firewall to see whether it is blocking the connection.

On Debian and Arch-based Linux distributions.

sudo ufw disable

On RHEL-based distributions and openSUSE.

sudo systemctl disable firewalld

The firewall blocked the connection if the error did not occur after deactivating it. Re-enable the firewall and create a rule that enables SSH in this circumstance. For example, use the following command to enable SSH in the UFW firewall based on Debian and Arch on Linux distributions.

sudo ufw allow ssh

You may also allow SSH by the port number in the firewall. For example, if the SSH server uses port 5555, you will use the following command to let it over the firewall.

sudo ufw allow 5555

Check the UFW status to verify whether the rule was successfully added.

sudo ufw status

Use the following command to enable SSH in the firewall on RHEL-based systems and openSUSE.

sudo firewall-cmd --permanent --add-service=ssh

Use the following command to enable SSH via port number.

sudo firewall-cmd --permanent --add-port={port}/tcp

The command would be for an SSH server running on port 4444.

sudo firewall-cmd --permanent --add-port=4444/tcp

Run to verify that the rule was successfully added to the firewall.

sudo firewall-cmd --list-all

Resolve IP Address Conflicts

The SSH server IP may clash with another system’s IP on the network, resulting in the SSH “connection refused” error. This occurs when two systems on a network claim to have the same IP address, resulting in an IP conflict. Use the arp-scan tool to see whether there is an IP conflict in your network.

arp-scan [network-id]

The duplicate IP address will be displayed in the output if there is an IP dispute. For example, an IP dispute in a network is seen in the screenshot below.

Ensure no devices have static IP addresses contradicting the DHCP pool addresses to prevent IP conflicts.

Tip: Run SSH In Verbose Mode

If you get an SSH error, try running the ssh command in verbose mode to find the issue. For example, use the ssh command with the -vvv option to execute SSH in verbose mode.

ssh -vvv username@ip_address

In verbose mode, debugging messages will appear at each connection step, assisting you in determining the source of the issue.


The SSH “connection refused” error may be troubleshot and resolved by identifying the various reasons for the SSH connectivity error and executing the offered remedies. In addition to these instructions, connect to the proper IP address and use the correct login credentials. On Linux, you may enable two-factor authentication for SSH to make your remote connection more secure.

Related Articles

Back to top button