AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1217877
Accepted
Mate de Vita
Mate de Vita
Asked: 2020-03-18 08:10:45 +0800 CST2020-03-18 08:10:45 +0800 CST 2020-03-18 08:10:45 +0800 CST

通过 WSL 连接进行 X11 转发

  • 772

我有以下设置:

我的工作计算机正在运行 Ubuntu 18.04,具有以下内容/etc/ssh/sshd_config:

#       $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 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/bin:/bin:/usr/sbin:/sbin

# 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 override the
# default value.

Port 3022
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

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

PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# 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 no
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

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

# GSSAPI options
#GSSAPIAuthentication no
#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

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

# no default banner path
Banner /etc/issue.net
PrintMotd yes

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

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

# Example of overriding settings on a per-user basis
Match User me
        AllowAgentForwarding yes
        AllowTcpForwarding yes
        X11Forwarding yes
        X11UseLocalhost no
        PermitTunnel yes

我目前没有物理访问工作计算机的权限。所以我从家里连接到它。我的家用 PC 运行的是 Windows 10,其 Windows Subshel​​l for Linux 运行 Ubuntu 18.04。其中~/.ssh/config包含以下内容:

# Defaults
Host *
        ForwardAgent no
        ForwardX11 no
        ForwardX11Trusted no
        User me
        Protocol 2
        ServerAliveInterval 0
        TcpKeepAlive no

# Workstation
Host workcomputer
        HostName machine.domain.com
        Port 3022
        ForwardX11 Yes
        ForwardX11Trusted Yes

并~/.profile包含该行

DISPLAY=:0

家用计算机还安装并运行了 VcXsrv。

我能够像xeyes本地一样运行应用程序,并且它们在 VcXsrv 窗口中打开得很好(尽管我需要运行它,xeyes -display :0因为xeyes似乎没有使用 $DISPLAY 变量)。但是,我无法显示任何远程 GUI 应用程序。

me@Home:~$ ssh workcomputer
me@Work:~$ echo $DISPLAY

me@Work:~$ gedit
Unable to init server: Could not connect: Connection refused

(gedit:20107): Gtk-WARNING **: 16:58:42.096: cannot open display:

我试过export DISPLAY=:0在远程机器gedit上运行,之后确实运行了,但没有出现在我的本地机器上的 VcXsrv 窗口中。我也尝试过export DISPLAY=:10,但这再次导致Connection refused. 我也尝试过连接,ssh -X但也没有用。

我还能尝试在本地 X 服务器上打开远程 GUI 应用程序吗?

xorg ssh x11-forwarding windows-subsystem-for-linux
  • 1 1 个回答
  • 4340 Views

1 个回答

  • Voted
  1. Best Answer
    Mate de Vita
    2020-03-19T04:08:01+08:002020-03-19T04:08:01+08:00

    所以我终于设法使这项工作正常进行。要做的几件事(除了原始帖子):

    1. 在本地和远程安装 xauth 并为:0.

       sudo apt install xauth
       xauth generate :0 . trusted
      

    远程可能需要也可能不需要,但本地肯定需要消除有关丢失身份验证数据的警告。根据您的 xauth 安装位置,这也可能在本地需要。

    1. 在本地将这条确切的行(不缩短或省略任何内容)放入~/.bashrc(从 中删除~/.profile):

       export DISPLAY=localhost:0.0
      

    3. 即使ForwardX11和在您ForwardX11Trusted的 中设置为,在连接时使用(或者如果您不信任连接)开关:Yes~/.ssh/config-Y-X

        ssh -Y workcomputer
    

    我不确定为什么需要这样做,但由于某种原因,如果没有我的开关,它就不会转发 X11。

    更新

    关于第三点,-Y我需要切换的原因是我的 ssh 配置文件不正确地在顶部有默认值。排序很重要(使用每个参数的第一个匹配项),因此适当的修复,而不是总是使用-Y,是反转~/.ssh/config文件中的条目:

    # Workstation
    Host workcomputer
            HostName machine.domain.com
            Port 3022
            ForwardX11 Yes
            ForwardX11Trusted Yes
    
    # Defaults
    Host *
            ForwardAgent no
            ForwardX11 no
            ForwardX11Trusted no
            User me
            Protocol 2
            ServerAliveInterval 0
            TcpKeepAlive no
    
    • 2

相关问题

  • xorg 中是否有用于更改视频驱动程序的 GUI?

  • 类似于 Eyefinity 的东西?

  • 如何重置我的键盘布局?

  • 帮助让 Flash 播放器在第二个屏幕上工作?

  • 如何与无头服务器进行图形交互?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve