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:
- Open PuTTY configuration interface, navigate to
Connection→SSH→X11node - Check the
Enable X11 forwardingcheckbox - Enter
localhost:0.0in theX display locationfield - 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 10These 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 -clipboardWhere :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 6010When successful, the xclock application window should display on the local Xming server.
Common Issue Handling
If connection problems persist, check the following aspects:
- Firewall settings: Ensure local port 6010 (corresponding to display :10.0) is not blocked
- Xming permissions: Run Xming as administrator to ensure sufficient privileges for display creation
- SSH restart: Restart SSH service after configuration changes:
service sshd restart
Alternative Solutions and Tool Recommendations
For users experiencing persistent X11 forwarding issues, consider integrated solutions:
- MobaXterm: Built-in X11 server and SSH client, simplifying configuration process
- XQuartz: X11 server implementation for macOS platform
- VcXsrv: Open-source X11 server alternative for Windows platform
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:
- Xming starts and listens on
:0display - PuTTY establishes SSH connection and sets up X11 forwarding
- Remote shell sets
DISPLAY=localhost:10.0 - X applications connect to forwarding endpoint
- 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.