我有以下设置:
我的工作计算机运行的是 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
我目前无法物理访问工作计算机。因此,我在家里连接它。我的家用电脑运行的是 Windows 10,带有运行 Ubuntu 18.04 的 Linux 版 Windows Subshell。其中~/.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 应用程序?
答案1
所以我终于设法让它正常工作了。除了原始帖子外,还有几件事要做:
在本地和远程安装 xauth 并生成条目
:0
。sudo apt install xauth xauth generate :0 . trusted
这在远程可能需要也可能不需要,但在本地肯定是需要的,以消除有关缺少身份验证数据的警告。这根据 xauth 的安装位置,可能还需要在本地进行。
在本地,将这一行(不缩短或省略任何内容)放入
~/.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