Windows 10客户端连接树莓派4服务器时OpenSSH未请求X11转发且无相关日志问题
Windows 10客户端连接树莓派4服务器时OpenSSH未请求X11转发且无相关日志问题
问题背景
I can't see any message relating to X11 forwarding.
I am using windows 10 as a client and the Raspberry pi 4( debian buster) as a server
执行ssh pi4 -Y -v命令后,得到的日志输出如下:
steven@DESKTOP-8EMNIS1 ~ $ ssh pi4 -Y -v OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2 debug1: Connecting to pi4 [fe80::b5d0:4a20:7aac:baea%3] port 22. debug1: Connection established. debug1: identity file C:\\Users\\steven/.ssh/id_rsa type -1 debug1: identity file C:\\Users\\steven/.ssh/id_rsa-cert type -1 debug1: identity file C:\\Users\\steven/.ssh/id_dsa type -1 debug1: identity file C:\\Users\\steven/.ssh/id_dsa-cert type -1 debug1: identity file C:\\Users\\steven/.ssh/id_ecdsa type -1 debug1: identity file C:\\Users\\steven/.ssh/id_ecdsa-cert type -1 debug1: identity file C:\\Users\\steven/.ssh/id_ed25519 type -1 debug1: identity file C:\\Users\\steven/.ssh/id_ed25519-cert type -1 debug1: identity file C:\\Users\\steven/.ssh/id_xmss type -1 debug1: identity file C:\\Users\\steven/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1 debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Raspb ian-10+deb10u2+rpt1 debug1: match: OpenSSH_7.9p1 Raspbian-10+deb10u2+rpt1 pat OpenSSH* compat 0x0400 0000 debug1: Authenticating to pi4:22 as 'steven' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit > compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit > compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ecdsa-sha2-nistp256 SHA256:ubyhDQ0qt2j1WcMpHZlhbnGdzenQ e6vf5ON+bm08LRI debug1: Host 'pi4' is known and matches the ECDSA host key. debug1: Found key in C:\\Users\\steven/.ssh/known_hosts:6 debug1: rekey out after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey in after 134217728 blocks debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory debug1: Will attempt key: C:\\Users\\steven/.ssh/id_rsa debug1: Will attempt key: C:\\Users\\steven/.ssh/id_dsa debug1: Will attempt key: C:\\Users\\steven/.ssh/id_ecdsa debug1: Will attempt key: C:\\Users\\steven/.ssh/id_ed25519 debug1: Will attempt key: C:\\Users\\steven/.ssh/id_xmss debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rs a-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521> debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,password debug1: Next authentication method: publickey debug1: Trying private key: C:\\Users\\steven/.ssh/id_rsa debug1: Trying private key: C:\\Users\\steven/.ssh/id_dsa debug1: Trying private key: C:\\Users\\steven/.ssh/id_ecdsa debug1: Trying private key: C:\\Users\\steven/.ssh/id_ed25519 debug1: Trying private key: C:\\Users\\steven/.ssh/id_xmss debug1: Next authentication method: password debug1: read_passphrase: can't open /dev/tty: No such file or directory
你好!从你的描述和日志来看,现在遇到了两个关联的问题:一是整个SSH连接过程完全没有X11转发相关的日志输出,二是密码输入环节出现了/dev/tty找不到的错误。咱们一步步来解决:
一、解决X11转发无日志的问题
1. 先检查树莓派服务器的SSH配置
X11转发功能需要服务器端先开启,这是最常见的原因:
- 登录树莓派,编辑SSH服务的配置文件:
sudo nano /etc/ssh/sshd_config - 找到以下几个配置项,确保它们没有被注释(去掉前面的
#),并设置为对应的值:X11Forwarding yes X11DisplayOffset 10 X11UseLocalhost yes - 保存退出后,重启SSH服务让配置生效:
sudo systemctl restart ssh
2. 确认Windows客户端的X服务器环境
Windows本身不带X服务器,你需要安装第三方工具,比如VcXsrv或者Xming:
- 安装完成后,启动X服务器时一定要勾选Disable access control选项,不然树莓派的X11请求会被拒绝。
- 确保在你执行SSH连接时,X服务器是处于运行状态的。
3. 调整SSH连接参数测试
你现在用的-Y是信任X11转发的参数,可以试试加上-X(非信任模式),或者单独用-X来连接,看看日志里会不会出现X11相关的内容:
ssh pi4 -X -v
如果服务器配置没问题,这时候日志里应该会出现类似debug1: Requesting X11 forwarding with authentication spoofing.的条目。
二、解决read_passphrase: can't open /dev/tty错误
这个错误是因为Windows的OpenSSH在某些终端环境下没法找到模拟的终端设备,推荐两种解决办法:
1. 换用合适的终端环境
别用传统的CMD窗口执行SSH命令,改用PowerShell或者Windows Terminal,这两个终端对tty的支持更好,基本能解决这个问题。
2. 配置密钥登录替代密码登录
密钥登录不仅能避免密码输入的麻烦,还能彻底解决这个tty错误:
- 在Windows的PowerShell里生成SSH密钥对:
一路按回车用默认配置就行,密钥会存在ssh-keygenC:\Users\steven\.ssh\目录下。 - 把公钥复制到树莓派:
如果ssh-copy-id steven@pi4ssh-copy-id用不了,你可以手动复制id_rsa.pub里的内容,粘贴到树莓派的~/.ssh/authorized_keys文件里。 - 最后调整树莓派上密钥文件的权限(这一步很重要,不然密钥登录会失败):
之后再用chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keysssh pi4 -Y -v连接,就不用输密码了,也不会再出现tty相关的错误。
备注:内容来源于stack exchange,提问作者ageis23
相关产品推荐
相关产品推荐

