Resolving PuTTY X11 Forwarding Failure: Network Error: Connection Refused

Nov 28, 2025 · Programming · 11 views · 7.8

Keywords: PuTTY | X11 forwarding | Xming

Abstract: This article provides a comprehensive analysis of the "Network error: Connection refused" error encountered during X11 forwarding using PuTTY and Xming. Through detailed examination of SSH configuration, X11 server settings, and client configuration, it offers complete troubleshooting solutions including proper X display location setup, verification of X11 forwarding configuration, and handling of common environment issues. Content covers CentOS system configuration, PuTTY advanced settings, and Xming log analysis to help users thoroughly resolve X11 forwarding connection problems.

Problem Background and Error Phenomenon

When using PuTTY to connect to a CentOS 6.3 VPS via SSH and attempting to run the startx command, the system returns the error message: PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused. Simultaneously, executing xhost + and gedit commands produces similar errors, indicating inability to open display localhost:10.0.

Root Cause Analysis

The core cause of this error is PuTTY's failure to correctly identify the X11 server location. Although the SSH server configuration has X11Forwarding yes enabled, the client does not specify the X display location, causing connection requests to fail routing to the correct X server instance.

From the Xming logs, we can see the server successfully starts and listens on 127.0.0.1:10.0, but PuTTY's default configuration does not include this information. The environment variable DISPLAY=localhost:10.0 is correctly set on the server side, but the client forwarding mechanism fails to establish an effective connection.

Solution Implementation

Configuring PuTTY X11 Forwarding

In the PuTTY session configuration, the X display location must be explicitly specified:

  1. Open PuTTY configuration interface, navigate to ConnectionSSHX11 node
  2. Check the Enable X11 forwarding checkbox
  3. Enter localhost:0.0 in the X display location field
  4. Keep other X11 authentication settings at default values

This configuration ensures PuTTY correctly forwards X11 traffic to the local Xming server instance.

Verifying SSH Server Configuration

Check the /etc/ssh/sshd_config file on the VPS to confirm the following key parameters:

X11Forwarding yes
X11UseLocalhost yes
X11DisplayOffset 10

These settings allow the SSH server to handle X11 forwarding requests and assign independent display numbers for each session.

Xming Server Configuration

Ensure Xming starts with correct parameters:

Xming :0 -multiwindow -clipboard

Where :0 specifies the display number, corresponding to localhost:0.0 in PuTTY configuration. The -multiwindow and -clipboard parameters provide enhanced window management and clipboard functionality.

Troubleshooting and Verification

Connection Testing Steps

After configuration completion, verify X11 forwarding functionality through the following steps:

# Check DISPLAY variable after connection
echo $DISPLAY
# Should output something like localhost:10.0

# Test simple X application
xclock

# Check X11 connection status
netstat -an | grep 6010

When successful, the xclock application window should display on the local Xming server.

Common Issue Handling

If connection problems persist, check the following aspects:

Alternative Solutions and Tool Recommendations

For users experiencing persistent X11 forwarding issues, consider integrated solutions:

These tools typically provide more intuitive configuration interfaces and better compatibility, especially suitable for users unfamiliar with X11 underlying configuration.

Technical Principle Deep Dive

X11 forwarding is based on SSH's port forwarding mechanism. When X11 forwarding is enabled, the SSH client opens a Unix domain socket or TCP port locally, listening for X11 connection requests. Remote applications connect to this endpoint via the address specified in the DISPLAY environment variable, with the SSH tunnel securely transmitting traffic to the local X server.

Key component interaction flow:

  1. Xming starts and listens on :0 display
  2. PuTTY establishes SSH connection and sets up X11 forwarding
  3. Remote shell sets DISPLAY=localhost:10.0
  4. X applications connect to forwarding endpoint
  5. SSH tunnel transmits X protocol data to local X server

Understanding this flow helps diagnose more complex connection issues, particularly in scenarios involving network address translation (NAT) or complex firewall rules.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.