我有以下设置:
我的工作计算机正在运行 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 Subshell 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 应用程序吗?
所以我终于设法使这项工作正常进行。要做的几件事(除了原始帖子):
在本地和远程安装 xauth 并为
:0
.远程可能需要也可能不需要,但本地肯定需要消除有关丢失身份验证数据的警告。根据您的 xauth 安装位置,这也可能在本地需要。
在本地将这条确切的行(不缩短或省略任何内容)放入
~/.bashrc
(从 中删除~/.profile
):3. 即使ForwardX11
和在您ForwardX11Trusted
的 中设置为,在连接时使用(或者如果您不信任连接)开关:Yes
~/.ssh/config
-Y
-X
我不确定为什么需要这样做,但由于某种原因,如果没有我的开关,它就不会转发 X11。更新
关于第三点,
-Y
我需要切换的原因是我的 ssh 配置文件不正确地在顶部有默认值。排序很重要(使用每个参数的第一个匹配项),因此适当的修复,而不是总是使用-Y
,是反转~/.ssh/config
文件中的条目: