问题

问题

问题

我无法再以普通用户身份通过​​ ssh 进行 X11 转发。几个月前还可以,所以有些东西被无意间改变了。

我尝试过的方法

与 sudo 配合使用:

据我所知,我的 ssh 和 sshd 配置是正确的。事实上,如果我以 root 身份使用 sudo 运行,X11 就会正确转发:

$ ssh -X lm@<ip> -i <key>

lm@localhost:~$ xeyes
Error: Can't open display: localhost:10.0

lm@localhost:~$ sudo xeyes

lm@localhost:~$

成功转发 Xsudo 似乎是一个常见问题,但这是一个相反的问题。我不太明白我所看到的关于以 root 或其他用户身份进行 X 转发的信息,而且我根本不需要以 root 或其他用户身份进行转发。所以,我怎样才能将其恢复正常?

验证

我觉得这是一个身份验证问题。不过,我不确定如何判断它是否正确。

用户的 .Xauthority 中有两个条目

lm@localhost:~$ xauth info
Authority file:       /home/lm/.Xauthority
File new:             no
File locked:          no
Number of entries:    2
Changes honored:      yes
Changes made:         no
Current input:        (argv):1

lm@localhost:~$ xauth list
edare-fmt17138762/unix:10  MIT-MAGIC-COOKIE-1  48081e511d8ba861ccaf146b73a01617
localhost/unix:10  MIT-MAGIC-COOKIE-1  ce23a352c8f10814e103474aa620fc31

我尝试删除 .Xauthority,但问题并没有解决。

可能相关的主机名问题

主机名应该edare-fmt17138762,但每次重启都会重置。我尝试过再次设置主机名,也尝试过将主机名完全重置为 localhost,但这些都对转发 X 没有任何影响,所以似乎主机名不是问题所在。

sshd_config 更改

我尝试使用,X11UseLocalhost yes但没有效果。

我也尝试过X11UseLocalhost no,但它给出了额外的、略有不同的错误:

$ ssh -Y [email protected] -i <key>
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Last login: Thu Mar  1 14:51:41 2018 from 192.168.0.2
/usr/bin/xauth: (stdin):1:  bad display name "edare-fmt17138762:10.0" in "remove" command
/usr/bin/xauth: (stdin):2:  bad display name "edare-fmt17138762:10.0" in "add" command
lm@edare-fmt17138762:~$ xeyes
Error: Can't open display: edare-fmt17138762:10.0

设置显示

我还尝试将 DISPLAY 变量设置为127.0.0.1:10.0

lm@edare-fmt17138762:~$ export DISPLAY='192.168.0.15:10.0'
lm@edare-fmt17138762:~$ xeyes
X11 connection rejected because of wrong authentication.
Error: Can't open display: 192.168.0.15:12.0

SSH 配置

服务器

Ubuntu 16.04 运行标准 OpenSSH。

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

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

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin prohibit-password
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

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

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

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

# Change to no to disable tunnelled clear text passwords
    PasswordAuthentication no

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

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

Subsystem sftp /usr/lib/openssh/sftp-server

# 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 yes
    PasswordAuthentication no

客户

几个客户端都存在同样的问题,不过以前都可以正常工作:另一台 Ubuntu 16.04 机器上的 OpenSSH 和 Windows 10 上的 puTTy。

SSH-V

OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.0.15 [192.168.0.15] port 22.
debug1: Connection established.
debug1: identity file <my file> type 1
debug1: key_load_public: No such file or directory
debug1: identity file <my file> type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.0.15:22 as 'lm'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:WVq6hBhuqXF99QGeoyfeiLYk+l7fJOGqpyk52roqdcE
debug1: Host '192.168.0.15' is known and matches the ECDSA host key.
debug1: Found key in /home/jmilloy/.ssh/known_hosts:34
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: <my key>
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.0.15 ([192.168.0.15]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: exec
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Requesting X11 forwarding with authentication spoofing.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-93-generic x86_64)

答案1

关于主机名重置,请检查您是否安装并配置了 cloud-config 之类的东西。它确实会弄乱一些东西,您可能需要更改某些选项,例如 update_hostname 或 set_hostname。

关于该问题,请尝试将以下内容添加到您的 sshd_config 并重新启动 sshd。

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
AddressFamily inet

答案2

遇到了同样的问题,解决方案是:我的主机名(cat /etc/hostname)不在/etc/hosts

我的 IP 地址有一个不同的名称定义在/etc/hosts

答案3

/etc/hosts必须是可读的。我的/etc/hosts权限是-rw-r-----,更改为-rw-r--r--解决了该问题。

相关内容