Forward X11 failed: Network error: Connection refused

Forward X11 failed: Network error: Connection refused

我有一个 VPS,OS 是 CentOS6.3。我想通过 PuTTY 和 Xming 运行 startx

但是,它产生了这个错误:

PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused

整体情况:

Using username "root".
Authenticating with public key "rsa-key-20150906" from agent
Last login: Thu Jan 21 13:53:40 2016 from 222.222.150.82
[root@mairo ~]# xhost +
PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused
xhost:  unable to open display "localhost:10.0"
[root@mairo ~]# echo $DISPLAY
localhost:10.0
[root@mairo ~]# gedit
PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused
(gedit:6287): Gtk-WARNING **: cannot open display: localhost:10.0
[root@mairo ~]#

这是 Xming 日志:

Welcome to the Xming X Server
Vendor: Colin Harrison
Release: 6.9.0.31
FreeType2: 2.3.4
Contact: http://sourceforge.net/forum/?group_id=156984

Xming :10 -multiwindow -clipboard 

XdmcpRegisterConnection: newAddress 192.168.139.1
winAdjustVideoModeShadowGDI - Using Windows display depth of 32 bits per pixel
winAllocateFBShadowGDI - Creating DIB with width: 1366 height: 768 depth: 32
winInitVisualsShadowGDI - Masks 00ff0000 0000ff00 000000ff BPRGB 8 d 24 bpp 32
glWinInitVisuals:1596: glWinInitVisuals
glWinInitVisualConfigs:1503: glWinInitVisualConfigs glWinSetVisualConfigs:1581: glWinSetVisualConfigs
init_visuals:1055: init_visuals
null screen fn ReparentWindow
null screen fn RestackWindow
InitQueue - Calling pthread_mutex_init
InitQueue - pthread_mutex_init returned
InitQueue - Calling pthread_cond_init
InitQueue - pthread_cond_init returned
winInitMultiWindowWM - Hello
winInitMultiWindowWM - Calling pthread_mutex_lock ()
winMultiWindowXMsgProc - Hello
winMultiWindowXMsgProc - Calling pthread_mutex_lock ()
glWinScreenProbe:1390: glWinScreenProbe
fixup_visuals:1303: fixup_visuals
init_screen_visuals:1336: init_screen_visuals
(--) 5 mouse buttons found
(--) Setting autorepeat to delay=500, rate=31
(--) winConfigKeyboard - Layout: "00000804" (00000804) 
(EE) Keyboardlayout "Chinese (Simplified) - US Keyboard" (00000804) is unknown
Could not init font path element D:\Program Files (x86)\Xming/fonts/misc/, removing from list!
Could not init font path element D:\Program Files (x86)\Xming/fonts/TTF/, removing from list!
Could not init font path element D:\Program Files (x86)\Xming/fonts/Type1/, removing from list!
Could not init font path element D:\Program Files (x86)\Xming/fonts/75dpi/, removing from list!
Could not init font path element D:\Program Files (x86)\Xming/fonts/100dpi/, removing from list!
Could not init font path element C:\Program Files\Xming\fonts\dejavu, removing from list!
Could not init font path element C:\Program Files\Xming\fonts\cyrillic, removing from list!
Could not init font path element C:\WINDOWS\Fonts, removing from list!
winInitMultiWindowWM - pthread_mutex_lock () returned.
winInitMultiWindowWM - pthread_mutex_unlock () returned.
winInitMultiWindowWM - DISPLAY=127.0.0.1:10.0
winMultiWindowXMsgProc - pthread_mutex_lock () returned.
winMultiWindowXMsgProc - pthread_mutex_unlock () returned.
winMultiWindowXMsgProc - DISPLAY=127.0.0.1:10.0
winProcEstablishConnection - Hello
winInitClipboard ()
winProcEstablishConnection - winInitClipboard returned.
winClipboardProc - Hello
DetectUnicodeSupport - Windows Vista
winClipboardProc - DISPLAY=127.0.0.1:10.0
winInitMultiWindowWM - XOpenDisplay () returned and successfully opened the display.
winMultiWindowXMsgProc - XOpenDisplay () returned and successfully opened the display.
winClipboardProc - XOpenDisplay () returned and successfully opened the display.

这是我在 VPS 上的 sshd_config

#   $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing, 
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
GatewayPorts yes
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem   sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#   X11Forwarding no
#   AllowTcpForwarding no
#   ForceCommand cvs server

并且我启用了X11转发

导致上述错误的原因是什么?


新增详情

根据@lilydjwg的回答,我已经填好了"X display location"然后再试,还是报错:

Using username "root".
Authenticating with public key "rsa-key-20150906" from agent
Last login: Thu Jan 21 22:24:57 2016 from 222.222.150.82
[root@mairo ~]# echo $DISPLAY
localhost:10.0
[root@mairo ~]# gedit
process 6968: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open"/var/lib/dbus/machine-id": No such file or directory
See the manual page for dbus-uuidgen to correct this issue.
  D-Bus not built with -rdynamic so unable to print a backtrace
Aborted
[root@mairo ~]#

PuTTY 无法找到您的 X 服务器的位置,因为您没有告诉它。 (Linux 上的 ssh 没有这个问题,因为它在 X 下运行,所以它只使用那个。)在 "X display location" 之后的空白框中填写您的 Xming 服务器地址。

或者,尝试 MobaXterm。它有一个内置的 X 服务器。

D-Bus 错误可以用 dbus-launch 修复:

dbus-launch command

其他答案已过时、不完整或根本不起作用。

您还需要在主机上指定一个 X-11 服务器来处理 GUId 程序的启动。如果客户端是 Windows 机器,请安装 Xming。 如果客户端是 Linux 机器,请安装 XQuartz。

现在假设这是 Windows 连接到 Linux。为了能够在 putty 上启动 X11 程序,请执行以下操作:

- Launch XMing on Windows client
- Launch Putty
    * Fill in basic options as you know in session category
    * Connection -> SSH -> X11
        -> Enable X11 forwarding
        -> X display location = :0.0
        -> MIT-Magic-Cookie-1
        -> X authority file for local display = point to the Xming.exe executable

当然,ssh 服务器应该允许桌面共享 "Allow other user to view your desktop"。

MobaXterm 和其他完整的远程桌面程序也可以。

你应该安装一个 x 服务器,比如 XMing。并保持 x 服务器为 运行。 像这样配置你的腻子:应该检查Connection-Data-SSH-X11-Enable X11 forwarding。和 X 显示位置:localhost:0

不要以 root 用户身份登录,尝试另一个具有 sudo 权限的用户。

填写 "X display location" 对我没用。 但安装 MobaXterm 完成了工作。

我也遇到过同样的问题,现在已经解决了。 最后,Putty 确实可以与 Cigwin-X 一起使用,并且 Xming 不是 MS-Windows X-server 的强制性应用程序。

现在是xlaunch,控制X-window的运行。 当然,Cigwin 必须安装xlaunch.exe。 当 运行 在交互模式下它要求 "extra settings"。 您应该将“-listen tcp”添加到附加参数字段,因为默认情况下 Cigwin-X 不侦听 TCP。

为了不重复这些步骤,您可以将设置保存到文件中。并且 运行 xlaunch.exe 通过它的快捷方式,里面修改了 CLI。像

C:\cygwin64\bin\xlaunch.exe -run C:\cygwin64\config.xlaunch

X 显示位置:localhost:0 为我工作:)

Windows 10 - Xming.exe 到 Linux Debian 10 克星 X11

ssh.exe -X 不起作用,但 ssh.exe -Y 起作用。

感谢@KeyC0de 的回答,我已经使用 PuTTY.exe 从我的本地 Windows 10 成功连接到我的远程 Linux Debian box,启用使用 xterm 或其他 X11图形程序。

但是无法通过没有 PuTTY.exe 的 Windows 裸 ssh.exe 会话启动它们,即使 Xming.exe 安装在 Windows 10 本地主机中。

要使用裸 ssh.exe 可执行文件,然后在 Linux 下使用 xterm,我用这个方法成功了:

  1. 运行 Xming.exe 作为 Windows 下的 X11 终端服务器 10.
  2. 在 Windows DISPLAY="localhost:0"
  3. 上设置环境变量
  4. 运行 ssh.exe -Y user@example.com
  5. 运行 xterm 在 Linux.

在 PowerShell 中,我们这样做:

$env:DISPLAY="localhost:0"
ssh.exe -Y user@example.com

现在我们在linux远程盒子上,

我们这样启动 X11 程序:

$ xterm

大功告成。

ssh -Y Enables trusted X11 forwarding. Trusted X11 forwardings are not subjected to the X11 SECURITY extension controls.

参见 https://man.openbsd.org/ssh


如果您还在使用旧的 Windows 命令行提示符或 .bat 脚本,这是您的方法:

在 MS-DOS cmd.exe 控制台中,我们这样做:

SET DISPLAY=localhost:0
ssh.exe -Y user@example.com

Windows10 PowerShell 控制台上的插图:

在 Linux 上生成此 X11 小部件 window:

对我来说,这是一个简单的错误:Xming 不是 运行ning。请确保您的 Xming 进程 运行ning 在后台运行,否则它将无法运行。例如,如果您重新启动计算机,并且没有将 Xming 自动设置为 运行。

PuTTY 无法找到您的 X 服务器的位置,因为您没有告诉它。 (Linux 上的 ssh 没有这个问题,因为它在 X 下运行,所以它只使用那个。)用你的 Xming 服务器地址填​​写“X 显示位置”后的空白框。 或者,试试 MobaXterm。它有一个内置的 X 服务器。

尝试:在控制台中导出 DISPLAY=:0。