9.15 远程使用X Server https://scz.617.cn/unix/202103041210.txt Q: 我知道两种使用X Server的办法。一种是在主控台图形界面登录,自带X Server;另 一种是在Windows上运行各种PC X Server,在*nix上为X Client指定DISPLAY使之指 向Windows: export DISPLAY=:0.0 -display :0.0 关于DISPLAY的值参看X(7)手册。 有没有办法从Windows远程使用*nix上的X Server,让X Client、X Server都跑在 *nix上,同时还能远程使用? A: bluerust 2021-03-04 12:10 以Ubuntu/Debian为例 aptitude install xvfb x11vnc Xvfb :1 -screen 0 1024x768x16 & 启动X Server,displaynumber不要用0,一般主控台上那个已经是0了 此处不要用1024x768x32,会失败 x11vnc -display :1 -bg -nopw -xkb -listen 192.168.65.21 -rfbport 5901 侦听192.168.65.21:5901/TCP,缺省用5900,刻意演示更改端口 DISPLAY=:1 opera --ignore-urlfetcher-cert-requests --no-sandbox --ignore-certificate-errors http://checkip.dyndns.com 在前述X Server中启动特定X Client,本例是Opera 在Windows上用任意一款vncviewer连接192.168.65.21:5901 https://www.realvnc.com/en/connect/download/viewer/ VNC-Viewer-6.20.529-Windows-64bit.exe https://www.tightvnc.com/download.php tightvnc-2.8.59-gpl-setup-64bit.msi tightvnc-1.3.10_x86_viewer.zip 这些vncviewer都可以绿色化,单个文件随便拷走,最后一个通杀Win9x到Win10。 这样用X Client,可以在*nix和Windows之间copy/paste选中的内容。不要求主控台 有图形登录环境,特别适合临时使用X Client的场景。 关于x11vnc,有一些其他技巧,参看: https://ubuntuforums.org/showthread.php?t=1832456 Q: Xvfb :1 -screen 0 1626x935x16 & 启动X Server x11vnc -display :1.0 -bg -nopw -xkb -listen 192.168.65.26 -rfbport 5900 x11vnc -display :1.0 -bg -nopw -xkb -forever -listen 192.168.65.26 -rfbport 5900 x11vnc -display :1.0 -bg -nopw -xkb -noncache -forever -listen 192.168.65.26 -rfbport 5900 侦听192.168.65.26:5900/TCP DISPLAY=:1.0 /usr/bin/code 在前述X Server中启动特定X Client,本例是"Visual Studio Code" 在Windows上用任意一款vncviewer连接192.168.65.26:5900 X Server分辨率已经是1626x935,但X Client 仍然使用1024x768,怎么办? A: scz 2021-06-08 aptitude install xdotool 查看code的windowid DISPLAY=:1.0 xdotool search code DISPLAY=:1.0 xdotool search --onlyvisible code DISPLAY=:1.0 xdotool getwindowfocus 假设windowid是14680069 DISPLAY=:1.0 xdotool windowmove 14680069 0 0 // 定位窗口左上角 DISPLAY=:1.0 xdotool windowsize 14680069 1626 935 // 设定窗口大小 其他命令 DISPLAY=:1.0 xdotool windowclose 14680069 DISPLAY=:1.0 xdotool windowkill 14680069 DISPLAY=:1.0 xdotool windowfocus 14680069