第一步:禁用 Wayland,切换到 Xorg
Ubuntu 24.04 默认使用 Wayland,x11vnc 需要 Xorg 才能工作,必须先禁用 Wayland。
sudo vim /etc/gdm3/custom.conf
找到这一行,去掉注释:
WaylandEnable=false
保存后重启或重新登录。登录界面右下角选 "Ubuntu on Xorg"。
第二步:安装 x11vnc
sudo apt update
sudo apt install x11vnc -y
第三步:设置 VNC 密码
x11vnc -storepasswd ~/.vnc/passwd
第四步:启动 VNC
x11vnc -auth guess -forever -loop -noxdamage -repeat \
-rfbauth ~/.vnc/passwd -rfbport 5900 -shared -bg
连接地址:你的IP:5900
第五步(可选):设置开机自启
创建 systemd 服务文件:
sudo nano /etc/systemd/system/x11vnc.service
内容如下(替换 yourusername):
[Unit]
Description=Start x11vnc at startup
After=graphical.target
[Service]
Type=simple
User=yourusername
ExecStart=/usr/bin/x11vnc -auth /home/yourusername/.Xauthority \
-forever -loop -noxdamage -repeat \
-rfbauth /home/yourusername/.vnc/passwd -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable x11vnc
sudo systemctl start x11vnc
如果是多屏幕只共享其中一个
-clip 裁剪区域
xrandr
比如输出:
Screen 0: minimum 320 x 200, current 3840 x 1419, maximum 16384 x 16384
eDP-1 connected primary 1920x1200+1920+219 (normal left inverted right x axis y axis) 344mm x 215mm
2560x1600 120.01 + 120.01 60.00
2560x1440 120.01
2048x1536 120.01
1920x1440 120.01
1856x1392 120.01
1792x1344 120.01
2048x1152 120.01
1920x1200 120.01*
...
如果想只共享Screen 0, 则使用vnc启动命令为:
x11vnc -clip 1920x1200+1920+219 \
-auth guess -forever -loop -noxdamage -repeat \
-rfbauth ~/.vnc/passwd -rfbport 5903 -shared -bg
评论 · 0
发表评论