Monday, April 13, 2026

How to Fix “Connection Refused” Error in PuTTY While Accessing a Virtual Machine

Abstract

When attempting to access a virtual machine using PuTTY, users often encounter the error “Network error: Connection refused.” This issue indicates that the target system is reachable, but the SSH service is either not running or not accepting connections on the specified port. This blog provides a clear, practical, and technically grounded guide to diagnose and resolve the problem effectively.


Introduction

Secure remote access is a fundamental requirement in modern system administration. Tools like PuTTY allow users to connect to Linux-based virtual machines using the SSH protocol. However, connection errors can interrupt workflows, especially in environments such as Koha library systems or cloud-based servers.

One of the most common issues is:

PuTTY Fatal Error: Network error: Connection refused

Understanding the root cause is essential for resolving it quickly.


What Does “Connection Refused” Mean?

This error occurs when:

  • Your system successfully reaches the server’s IP address

  • But the server rejects the connection request on the specified port

Technically, this means:

  • No service (like SSH) is listening on that port

  • Or a firewall is actively blocking the connection


Step-by-Step Troubleshooting Guide

1. Verify SSH Service Status

The most common cause is that the SSH service is not running.

Log in to your VM locally (or via console) and run:

sudo systemctl status ssh

If inactive, start it:

sudo systemctl start ssh
sudo systemctl enable ssh

If SSH is not installed:

sudo apt update
sudo apt install openssh-server

2. Confirm SSH Port Configuration

SSH runs on port 22 by default, but it may be changed for security reasons.

Check configuration:

sudo nano /etc/ssh/sshd_config

Look for:

Port 22

If the port is different (e.g., 2222), update PuTTY accordingly.


3. Check Firewall Settings

On Ubuntu (UFW):

sudo ufw status

Allow SSH if needed:

sudo ufw allow 22
sudo ufw reload

A blocked port will prevent SSH connections even if the service is running.


4. Ensure SSH Port is Listening

Run:

ss -tulnp | grep :22

Expected output:

LISTEN 0 128 0.0.0.0:22

If no output appears, SSH is not active.


5. Test Connectivity from Client Machine

From your local computer:

ping 10.40.3.125
telnet 10.40.3.125 22

Interpretation:

  • Ping works → Network is fine

  • Telnet fails → SSH service issue


6. Check Virtual Machine Network Configuration

If using VMware or VirtualBox:

  • NAT mode may restrict access

  • Switch to Bridged Adapter for direct network access

This is a frequent issue in local virtual environments.


7. Restart SSH Service

After changes:

sudo systemctl restart ssh

8. Reconnect Using PuTTY

In PuTTY:

  • Host Name: 10.40.3.125

  • Port: 22 (or custom)

  • Connection Type: SSH

Click Open and log in.


Practical Insight: Why This Happens in Koha Environments

In systems like Koha (as seen in your case running on port 8080):

  • Web interface works → server is active

  • SSH fails → service not enabled or blocked

This often occurs in:

  • Fresh installations

  • Minimal Linux setups

  • Security-hardened environments


Security Considerations

  • Prefer key-based authentication over passwords

  • Restrict SSH access using firewall rules

  • Disable root login in production

  • Consider changing the default SSH port


Conclusion

The “Connection refused” error is not a network failure but a service-level issue. By systematically verifying SSH service status, port configuration, firewall rules, and VM networking, the problem can be resolved efficiently. Mastering these diagnostics is essential for anyone working with virtual machines, especially in research, library systems, and cloud environments.


Suggested Further Reading

To deepen your understanding, explore:

  • SSH Key-Based Authentication and Security

  • Linux System Services (systemctl)

  • Firewall Management (UFW and iptables)

  • Virtual Machine Networking (NAT vs Bridged)

  • Remote Server Administration Best Practices

  • Koha System Deployment and Server Configuration


References

  1. Barrett, D. J., Silverman, R. E., & Byrnes, R. G. SSH, The Secure Shell: The Definitive Guide. O’Reilly Media.

  2. Nemeth, E., Snyder, G., & Hein, T. UNIX and Linux System Administration Handbook. Pearson.

  3. Ubuntu Documentation. OpenSSH Server Guide.

  4. Ylonen, T., & Lonvick, C. (2006). The Secure Shell (SSH) Protocol Architecture. RFC 4251.


No comments:

Post a Comment

How to Install Elastic Search

📚 Why Elasticsearch + Unicode Matters Traditional search engines struggle with: Diacritics (e.g., زبر، زیر) Word variations Complex scripts...