Bobcares

How to resolve “localhost connection refused” error in PuTTY client?

by | Jan 22, 2019

PuTTY provides a convenient way to access servers.

But, things can go wrong when it can’t communicate with the server, and users see an error like “localhost connection refused” in their PuTTY client.

Is this a server side or a client side problem? Well, it can happen at both sides.

At Bobcares we help server owners resolve these errors as part of our Support Services for web hosts.

Today, we’ll discuss the top 5 reasons for this error and how we fix them.

 

‘localhost connection refused’ error in PuTTY – What’s this?

Users usually use the PuTTY client to access the server remotely through SSH.

A Connection refused error means that the server refused the connection made by the application. In a PuTTY client, users see the below error message when trying to connect to the server.

Putty Fatal Error
Network Error: Connection Refused

 

And, this means the connection to the SSH host is routed, but the host doesn’t accept that request.

 

‘localhost connection refused’ error in PuTTY – Causes & Fixes

Now let’s see the main reasons for this error in PuTTY client and how our Support Engineers help customers resolve this problem.

1) Firewall restrictions

Firewall blocking connections from a specific IP address/IP ranges or target SSH ports is one of the common reasons for this error.

We’ve seen cases in which the IP address or IP range of the customer is blocked on the server due to an abnormal behavior.

Similarly, server owners switch the default SSH port to a custom one, but failed to open that port on the server.

How we fix?

Firstly, our Hosting Engineers check that the IP address of the user is blocked in the server firewall. For example, we use the following command to check the rules in iptables firewall.

iptables -nL

 

And if it’s blocked, we unblock that IP address and restore the connectivity immediately. After that, we check the server logs to identify the reason for the block.

In addition to that, we check the connectivity to the SSH port with the telnet command.

telnet xx.xx.xx.xx 22

 

If we find any firewall rules that interfere with the connection to the SSH port, we’ll remove that rule from the firewall configuration.

For example, if we see a DROP or REJECT rule on SSH port for all connections, we’ll remove that rule from the firewall. Further, we edit the firewall configuration to accept all connections to the SSH port.

iptables -A INPUT -p tcp --dport 22 -j ACCEPT

2) Service Downtime

Similarly, another common reason for this error is that the SSH service is not running or the SSH server is broken.

In other words, SSH service uses sshd daemon to process incoming connections, authentication requests, etc. If this service fails, the PuTTY SSH client can’t communicate with the SSH server, resulting in ‘localhost connection refused‘ error.

 

How we fix?

The reason for service failure could be disk errors, resource outages, traffic spikes, etc. Our Hosting Engineers determine if the SSH service is listening using the netstat command.

If the service fails or doesn’t respond, we kill the dead process and restart the service. For example, we use the following command for restarting the SSH service on CentOS 7 servers.

systemctl restart sshd

 

Most importantly, we identify the reason for the service downtime and fix it permanently.

 

3) Custom SSH port

Standard SSH ports are prone to attacks. That’s why server owners enable SSH service on custom ports, which are hard to guess.

But, if the users access the server using the wrong port, they will be kicked out of the server with the error ‘localhost connection refused‘.

 

How we fix?

Inorder to confirm the SSH port, we access the server via Console and check the SSH configuration file /etc/sshd/sshd_config. The Port parameter specifies the SSH port used by the server. Alternatively, we use the netstat command to check the SSH port.

Once we identify the correct port, we check the SSH client details and confirm that custome ruses the correct port.

 

4) Wrong PuTTY configuration

Similarly, a common mistake we see is that customers configure SSH clients like PuTTY without the necessary parameters. Incorrect Host or IP address, SSH port, connection type, username, key file, etc. can block the connection to the server.

In addition to that, we see customers using wrong IP address or the IP address conflicts with the other server. In other words, multiple servers assigned with the same IP address. This can also result in connection problems.

 

How we fix?

Our Hosting Engineers get the PuTTY configuration details from the customer. And, we ensure that the Hostname/IP address, username, SSH port, connection type, etc. are correct.

Further, we use tools like nmap to identify the servers running on the network. If we find any IP conflicts, we change the IP address of the server after checking with the customer.

 

5) Incorrect SSH key

Similarly, most users prefer to use key based authentication instead of password authentication to improve the security of the account.

However, a wrong private key or incorrect permissions of the SSH key pair can sometimes block users.

How we fix?

To confirm if private key is causing problem, we create a new key pair and connect to the server. If this works, we update the customer to create a new key pair and connect to the server.

Similarly, our Hosting Engineers check the permission and ownership of the key files in .ssh folder. If any permission or ownership issues are noted, we’ll immediately correct them. Most importantly, we ensure correct permissions for .ssh/authorized_keys file, because it’s where the public key is stored.

 

Conclusion

In short, localhost connection refused error in PuTTY client can occur due to firewall restrictions, service downtime, and more. Today, we’ve discussed the top 5 reasons for this error and how our Support Engineers fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF