VNC-Server安裝配置詳解


1. 品類

  • tightvnc(已於2009年停止更新)
  • tigervnc
  • x11vnc

2. 安裝tigervnc

即vnc4server。

坑:

  • Qt運行報錯(xkb...)
  • QtCreator無法使用

3. x11vnc

  1. 安裝

    sudo apt-get install x11vnc

  2. 配置vnc密碼

    x11vnc -storepasswd

    默認生成到 $HOME/.vnc/passwd

  3. 啟動vnc服務

    x11vnc -forever -shared -rfbauth ~/.vnc/passwd

3.1. 運行報錯 & 解決

以上方法在Ubuntu18.04會遇到報錯:

** If NO ONE is logged into an X session yet, but there is a greeter login
   program like "gdm", "kdm", "xdm", or "dtlogin" running, you will need
   to find and use the raw display manager MIT-MAGIC-COOKIE file.
   Some examples for various display managers:

     gdm:     -auth /var/gdm/:0.Xauth
              -auth /var/lib/gdm/:0.Xauth
     kdm:     -auth /var/lib/kdm/A:0-crWk72
              -auth /var/run/xauth/A:0-crWk72
     xdm:     -auth /var/lib/xdm/authdir/authfiles/A:0-XQvaJk
     dtlogin: -auth /var/dt/A:0-UgaaXa

   Sometimes the command "ps wwwwaux | grep auth" can reveal the file location.

   Starting with x11vnc 0.9.9 you can have it try to guess by using:

              -auth guess

   (see also the x11vnc -findauth option.)

   Only root will have read permission for the file, and so x11vnc must be run
   as root (or copy it).  The random characters in the filenames will of course
   change and the directory the cookie file resides in is system dependent.

See also: http://www.karlrunge.com/x11vnc/faq.html

原因大概是因為,ubuntu18以后默認不再使用lightdm作為desktop管理器,這需要x11vnc指定配置dm。

解決方法:啟動lightdm: sudo lightdm &

然后執行: x11vnc -auth guess -forever -noxdamage -repeat -rfbauth /home/liang/.vnc/passwd -rfbport 5900 -shared

選項說明:

  • -forever, 在客戶端斷開連接時保持服務,而不是關閉
  • -loop, 在服務終止時進入循環,並自動重啟服務
  • -timeout, 在timeout時間內允許客戶端連接,否則將關閉服務
  • -capslock
  • -repeat
  • -bg

3.2. 系統默認啟動x11vnc

除非配置了默認啟動 lightdm ,否則x11vnc無法自啟(環境依賴)。

  1. 生成秘鑰: x11vnc -storepasswd

  2. 啟動配置: sudo vi /lib/systemd/system/x11vnc.service

    [Unit]
    Description=Start x11vnc at startup.
    After=multi-user.target
    
    [Service]
    Type=simple
    ExecStart=/usr/bin/x11vnc -auth guess -forever -noxdamage -repeat -rfbauth /home/liang/.vnc/passwd -rfbport 5900 -shared
    
    [Install]
    WantedBy=multi-user.target
    
  3. 啟動lightdm: sudo lightdm &

  4. 添加到服務中:

    sudo systemctl daemon-reload
    sudo systemctl enable x11vnc.service
    sudo systemctl start x11vnc.service
    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM