- How to solve ‘Connection refused’ errors in SSH connection?
- How to Fix Connection Refused by Port 22 Debian/Ubuntu
- Verify OpenSSH Installation on Your Linux System
- Check SSH Service
- Allow SSH in Firewall
- Resolve Duplicate IP Address Conflict
- Conclusion
- About the author
- Karim Buzdar
- How to fix SSH connection refused error in Manjaro Linux
- Possible causes and their solutions for “connection refused” error in Manjaro
- 1 – SSH service inactive
- 2 – SSH is not installed
- 3 – Firewall is blocking the SSH connection
- 4 – SSH is listening to a wrong port
- 5 – SSH port is closed
- Conclusion
- ssh connection refused
How to solve ‘Connection refused’ errors in SSH connection?
I have an Ubuntu Server 10.10 32-bit in my home. I’m making SSH connections to it from my PC via Putty. The problem is, sometimes I’m able to login seamlessly. However, sometimes it gives me an error like this: Network error: Connection refused. Then, I dont’t change anything, try to login a few times more, wait a while and try again. Sometimes I can log in, sometimes I cannot. It seems pretty random to me. What can I do to solve this? Edit: And Sometimes, Putty gives Network error: Software caused connection abort error after displaying login as: text. Here is the ping -t output:
Pinging 192.168.2.254 with 32 bytes of data: Reply from 192.168.2.254: bytes=32 time=6ms TTL=64 Reply from 192.168.2.254: bytes=32 time=65ms TTL=6 Reply from 192.168.2.254: bytes=32 time=88ms TTL=6 Reply from 192.168.2.254: bytes=32 time=1ms TTL=64 Reply from 192.168.2.254: bytes=32 time=3ms TTL=64 Reply from 192.168.2.254: bytes=32 time=1ms TTL=64 Reply from 192.168.2.254: bytes=32 time=1ms TTL=64 Reply from 192.168.2.254: bytes=32 time=1ms TTL=64 Reply from 192.168.2.254: bytes=32 time=1ms TTL=64
I turned off firewall of router, and everything seems to work now. Except for that, I still can’t enter my web server by typing external IP from my PC.
next time it craps out like that; run a ping on it again, does it still work? how many people ssh to this machine?
Exactly the same problem here, also getting a mix of successful connects (which then work for hours), ‘connection refused’ and ‘software caused connection abort’ after the login or password entry. To provide some additional details: in my case it’s a 64-bit virtual machine (running Ubuntu Server 10.10) on a Microsoft Hyper-V host, using the «old network card» emulation.
How to Fix Connection Refused by Port 22 Debian/Ubuntu
SSH provides a secure channel to access Linux servers. Sometimes we come across the error Connection refused while connecting to SSH servers. There could be several reasons behind the error like the SSH service is inactive, the port is blocked by UFW firewall, the server is using a different port, or because of some IP conflict. Today, we will explore different ways we can resolve the Connection Refused issue on an Ubuntu/Debian system.
Verify OpenSSH Installation on Your Linux System
First, check if OpenSSH is installed on your system or not. The command mentioned below will verify it.
If OpenSSH is installed, you will see the following output on the terminal.
In case OpenSSH is not installed, we will install it by executing the following command:
Check SSH Service
Let’s now check what’s the status of the SSH service on our system. It should be active or in the running state. The reason why you are getting a connection refused error could be the inactive state of SSH on your system. Run the following command to check the status:
The output tells us it is in the active (running state).
If your SSH service is inactive, you can start it by executing the following commands:
Check SSH Server Listening Port
Perhaps, you are connecting to the wrong port which is why you are getting a connection refused error. For example, the server is listening for a connection on port 1068 but you are trying to connect to port 22.
Before trying to connect, first, verify which port is being used by the SSH server to listen to new connections. If the server is listening on default port 22, then you can use the following command syntax to make a connection:
Issue the following command to check on which port the OpenSSH server is listening:
As we can see 22 port is in use by OpenSSH to listen to connections.
In case, some other port is being used in place of 22, you will issue the command like this:
Allow SSH in Firewall
A connection refused message could also be because the firewall on your system is blocking the SSH port. To allow the port through firewall, execute this command:
If a port other than 22 is being used, you will issue the command like this:
Once the rules are updated, you will get this output on the terminal:
Reload the firewall with this command to update the rules:
Now check the status of firewall to verify if the SSH port has been allowed or not.
You will see the following message if you are using port 2244 for SSH:
Resolve Duplicate IP Address Conflict
Another reason that may be causing this issue is a duplicate IP address. So, we need to verify if the system has a duplicate address or not. To do that, we need arping utility on our system. Install it using the following command:
Now, ping the server IP address using the command syntax below:
If you receive a reply from more than one MAC address, that means a duplicate IP address is running on the system. To resolve this issue, change the IP of the SSH server.
Conclusion
In today’s guide, we discussed several reasons that could be causing the Connection refused error and several ways to resolve this issue. This article will surely help you in troubleshooting the error.
About the author
Karim Buzdar
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.
How to fix SSH connection refused error in Manjaro Linux
SSH (an acronym of “Secure Shell” or “Secure Socket Shell”) enables the system administrators to establish a secure connection between client and host machines. SSH is used for making a secure connection, no matter if the network is secure or not. The connection using SSH is quite tricky therefore it requires intense attention. And if you have not covered all the aspects of making a connection, you may encounter “connection refused” error while connecting computers using SSH.
In this descriptive post, we have listed the causes of “connection refused” error in SSH and their possible fixes.
Possible causes and their solutions for “connection refused” error in Manjaro
There are multiple possibilities that you are getting the connection refused error in Manjaro Linux. In this section we are listing those errors and the relevant solutions as well.
1 – SSH service inactive
There is a possibility that your SSH service is not working properly, and it is causing an interruption in connection. Firstly, look for the status of the SSH service with the help of the command written below.
If the service is down, then it is recommended to restart and enable the SSH service. The commands provided below will assist you to restart, enable and check the status of SSH service:
$ sudo systemctl restart sshd.service
$ sudo systemctl enable sshd.service
$ sudo systemctl status sshd.service
If the problem still occurs, you may contact your hosting provider to fix the issue.
2 – SSH is not installed
There is a possibility that you do not have the OpenSSH (tool for SSH) installed on your system. To ensure the installation, check the version of OpenSSH with the help of the command written below.
If the above command returns an error (as in our case it returned connection refused), then it means the OpenSSH daemon is missing on your server. To get it, execute the command provided below:
3 – Firewall is blocking the SSH connection
If the SSH service is running properly and still you are not able to connect to the SSH server then the firewall may be blocking your SSH connections. Although disabling the firewall rules may put your system under a security risk, you have to allow SSH through the firewall. You can allow SSH over your firewall with the help of command provided below.
Note : The output below shows that the rules are already added for SSH service.
After doing so, it is recommended to reload the firewall with the help of the command written below.
You can check the status of the firewall and the following command shows the firewall is allowing connections at port 22.
If the SSH server is listening to a port other than 22 then you have to mention that port number. For instance, the command written below will allow SSH server at your selected port number.
4 – SSH is listening to a wrong port
Whenever a connection request is initiated, the default port of SSH(22) is used. One of the reasons for connection refused error is that you may have changed the port but you are trying to connect to the default port. You can check the SSH listening port by accessing the /etc/ssh/sshd_config file. For instance the command provided below will filter(with respect to port) the content of /etc/ssh/sshd_config.
Note : In our case the output shows that the port is 22.
Moreover, if the SSH port is changed from 22 then the connection syntax would be like shown below.
Note : The -p flag is used to make a connection at the desired port. It is observed that if the default port of SSH is changed to another port then you have to specify that port number.
5 – SSH port is closed
Whenever an attempt for a connection is made, SSH sends a request to the specific port. So, to make it successful, the SSH port needs to be opened. As SSH uses port 22, it is mandatory that SSH must allow all incoming connections at port 22. Firslty, check the port 22 is opened or not by using the command stated below.
If the status is listening(as shown in the output) then it’s alright, but if the port is closed then you can use the following ip tables command to open port 22.
There may be a possibility that you are using the wrong credentials and it is suggested to look for the IP address of the server that you want to connect to.
After getting the things on board, you can make an ssh connection as we have made using the command written below.
Note : The username in the above command is “adnan” whereas localhost acts as a hostname.
Conclusion
To make a secure connection using SSH, it is recommended to keep in mind the hurdles in establishing the connection. These hurdles initiate the connection refused error in SSH. This article lists down the reasons for connection refused error and the possible solutions are also listed. Majorly, there are five reasons provided here that may be creating the “connection refused error“. We have provided the possible solutions to all the reasons that are generating the connection refused error.
ssh connection refused
Hi I’m having a problem with my ssh, which is magically stopped working and I couldn’t figure out why. The message it give is:
ssh: connect to host port 22: Connection refused
Trying 127.0.0.1. telnet: Unable to connect to remote host: Connection refused
I tried the solutions that I saw in some similar cases [1] and [2] but it still didn’t solve my problem the entries and outputs are as follows:
>> sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT >> sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:ssh Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
Note that this was already ACCEPT I didn’t had any problem even before entering the command sudo iptables -A INPUT -p tcp —dport ssh -j ACCEPT . I also tried to reboot ssh but it didn’t change anything
>>netstat -a | egrep 'Proto|LISTEN' Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 localhost:20128 *:* LISTEN tcp 0 0 localhost:17600 *:* LISTEN tcp 0 0 localhost:20129 *:* LISTEN tcp 0 0 localhost:17603 *:* LISTEN tcp 0 0 localhost:21128 *:* LISTEN tcp 0 0 deathstar:domain *:* LISTEN tcp 0 0 localhost:ipp *:* LISTEN tcp 0 0 *:db-lsp *:* LISTEN tcp6 0 0 ip6-localhost:ipp [::]:* LISTEN tcp6 0 0 [::]:db-lsp [::]:* LISTEN
I don’t know what else to try so hope this is enough to solve the problem. Rest is added after @Ashu’s comment
>>netstat -l --numeric-ports | grep 22 unix 2 [ ACC ] STREAM LISTENING 1618183 @jack-com.canonical.Unity.Master.Scope.files.T1731348652205882 >>sudo iptables --list Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:ssh Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
>>ps aux | grep sshd jack 3711 0.0 0.0 15944 2220 pts/26 S+ 14:08 0:00 grep --color=auto sshd