Ssh 转发X11失败:网络错误:连接被拒绝

Ssh 转发X11失败:网络错误:连接被拒绝,ssh,x11,putty,xming,Ssh,X11,Putty,Xming,我有一个VPS,它的操作系统是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

我有一个VPS,它的操作系统是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\u配置

#   $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显示位置”,然后再试一次,但仍然是错误的:


PuTTY找不到您的X服务器在哪里,因为您没有告诉它。(Linux上的SSH不存在这个问题,因为它在X下运行,所以它只使用了一个。)在“X显示位置”之后,用XMin服务器的地址填入空白框。< /P>
或者,试试看。它内置了一个X服务器。

D-Bus错误可以通过dbus启动来修复:

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服务器应该允许桌面共享“允许其他用户查看您的桌面”


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

您应该安装一个x服务器,如XMing。并保持x服务器运行。
如下配置putty:应该检查Connection-Data-SSH-X11-Enable X11转发。和X显示位置:localhost:0

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

填写“X显示位置”对我不起作用。
但是安装完成了任务。

我也遇到了同样的问题,但现在问题解决了。 最后,Putty确实与Cigwin-X配合使用,而Xming不是MS Windows X-server的必选应用程序

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

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

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

X显示位置:本地主机:0 为我工作:)

Windows 10-Xming.exe到Linux Debian 10 buster X11
ssh.exe-X
不起作用,但
ssh.exe-Y
起作用。 感谢@KeyC0de的回答,我已经使用PuTTY.exe成功地从本地Windows 10连接到远程Linux Debian box,从而启用了xterm或其他X11图形程序

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

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

  • 在Windows 10下作为X11终端服务器运行Xming.exe
  • 在Windows显示上设置环境变量=“localhost:0”
  • 运行ssh.exe-Yuser@example.com
  • 在Linux下运行xterm
  • 在PowerShell中,我们执行以下操作:

    $env:DISPLAY="localhost:0"
    ssh.exe -Y user@example.com
    
    SET DISPLAY=localhost:0
    ssh.exe -Y user@example.com
    
    现在我们使用的是linux remote box

    我们启动X11计划如下:

    $ xterm
    
    完成了

    ssh-Y
    启用受信任的X11转发。不支持受信任的X11转发 受X11安全扩展控制


    如果您仍在旧的Windows命令行提示符下或在.bat脚本中,以下是您的方法:

    在MS-DOS cmd.exe控制台中,我们执行以下操作:

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

    Windows 10 PowerShell控制台上的插图:

    在Linux上生成此X11小部件窗口:


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

    否,您没有。你不能在putty上
    startx
    。@Jakuje不仅是startx,而且当我运行gedit时,它也会出错。我认为你的gedit问题与你的X连接无关。它找不到D总线连接,这通常是由窗口管理器启动的。试试像“xclock”这样的基本功能,看看是否有效。@JvO是的,一分钟后就可以了。但是仍然出现了一个警告
    警告:字符串到字体集转换中缺少字符集
    ,因此您的X连接正在工作;您只需要一些额外的组件,比如D-Bus守护进程。这些警告可能是由于缺少字体或区域设置造成的。顺便说一句,如果“xclock”需要一分钟来启动,那么你的X连接将非常慢……但是要填充什么呢?填充它
    localhost:10
    ?@TJM gedit正在使用D-Bus,所以您也应该转发它。实际上,有些应用程序即使在转发了D-Bus后也无法工作,例如evince。@lilyjwg那么,我该怎么办呢?有没有类似pac的东西可以指定哪个前进D-Bus和哪个不前进?@TJM否,D-Bus不使用JavaScript。您只需要一个D总线,无论是本地还是远程。感谢您使用术语
    xming
    。它提醒xterm需要一个显示服务器!我认为这是因为服务器的管理员在
    sshd\u config
    中禁用了
    permitrotlogin
    。如果已禁用,则无法以root用户身份登录该服务器。但是,从上面的问题来看,我已经以root身份登录了。因此,使用root不是X11转发失败的原因。如果启用了PermitroLogin,则无论X11转发如何,都可以通过SSH连接到服务器,这并不重要。同样,root用户会给你带来问题,你不应该为了安全而这样做,这不是一个好习惯。我建议您使用Cygwin/X,它更快更完整,但不是作为root用户。我正在用谷歌chrome做测试,效果很好(有点慢)