Ubuntu18.04 遠程命令行下安裝並啓動x11vnc

最近做項目需要連接ubuntu的圖像界面,開始用XQuartZ,界面太low太醜,而且有些應用啓動不了;後來轉到使用x11vnc,在網絡上查看了很多交安裝x11vnc的方法:

下面這種方法在Ubuntu18.04不能用

1.安裝
sudo apt-get install x11vnc
2.配置vnc密碼
x11vnc -storepasswd
3.啓動vnc服務
x11vnc -forever -shared -rfbauth ~/.vnc/passwd

會提示錯誤:

04/12/2019 14:14:51 passing arg to libvncserver: -rfbauth
04/12/2019 14:14:51 passing arg to libvncserver: /home/ml/.vnc/passwd
04/12/2019 14:14:51 x11vnc version: 0.9.13 lastmod: 2011-08-10  pid: 21722
04/12/2019 14:14:51 XOpenDisplay("") failed.
04/12/2019 14:14:51 Trying again with XAUTHLOCALHOSTNAME=localhost ...
04/12/2019 14:14:51 
04/12/2019 14:14:51 *** XOpenDisplay failed. No -display or DISPLAY.
04/12/2019 14:14:51 *** Trying ":0" in 4 seconds.  Press Ctrl-C to abort.
04/12/2019 14:14:51 *** 1 2 3 4 
Invalid MIT-MAGIC-COOKIE-1 key04/12/2019 14:14:55 XOpenDisplay(":0") failed.
04/12/2019 14:14:55 Trying again with XAUTHLOCALHOSTNAME=localhost ...
Invalid MIT-MAGIC-COOKIE-1 key04/12/2019 14:14:55 XOpenDisplay(":0") failed.
04/12/2019 14:14:55 Trying again with unset XAUTHLOCALHOSTNAME ...
Invalid MIT-MAGIC-COOKIE-1 key04/12/2019 14:14:55 

04/12/2019 14:14:55 ***************************************
04/12/2019 14:14:55 *** XOpenDisplay failed (:0)

*** x11vnc was unable to open the X DISPLAY: ":0", it cannot continue.
*** There may be "Xlib:" error messages above with details about the failure.

Some tips and guidelines:

** An X server (the one you wish to view) must be running before x11vnc is
   started: x11vnc does not start the X server.  (however, see the -create
   option if that is what you really want).

** You must use -display <disp>, -OR- set and export your $DISPLAY
   environment variable to refer to the display of the desired X server.
 - Usually the display is simply ":0" (in fact x11vnc uses this if you forget
   to specify it), but in some multi-user situations it could be ":1", ":2",
   or even ":137".  Ask your administrator or a guru if you are having
   difficulty determining what your X DISPLAY is.

** Next, you need to have sufficient permissions (Xauthority) 
   to connect to the X DISPLAY.   Here are some Tips:

 - Often, you just need to run x11vnc as the user logged into the X session.
   So make sure to be that user when you type x11vnc.
 - Being root is usually not enough because the incorrect MIT-MAGIC-COOKIE
   file may be accessed.  The cookie file contains the secret key that
   allows x11vnc to connect to the desired X DISPLAY.
 - You can explicitly indicate which MIT-MAGIC-COOKIE file should be used
   by the -auth option, e.g.:
       x11vnc -auth /home/someuser/.Xauthority -display :0
       x11vnc -auth /tmp/.gdmzndVlR -display :0
   you must have read permission for the auth file.
   See also '-auth guess' and '-findauth' discussed below.

** 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.04能夠成功啓動x11vnc:

 

1、安裝

sudo apt-get install x11vnc

2、生成密碼

sudo x11vnc -storepasswd

3、編輯啓動文 

sudo vi /lib/systemd/system/x11vnc.service

啓動文件內容(USERNAME要替換成自己的用戶名)

[Unit] 
Description=Start x11vnc at startup. 
After=multi-user.target 
 
[Service] 
Type=simple 
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/USERNAME/.vnc/passwd -rfbport 5900 -shared 
 
[Install] 
WantedBy=multi-user.target

4、另一個窗口啓動lightdm

sudo lightdm

5、 添加到服務中

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

6、重啓驗證服務(非必須步驟)

sudo reboot

 7、驗證x11vnc服務

sudo netstat -an | grep 5900
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN     
tcp6       0      0 :::5900                 :::*                    LISTEN

 連接登陸服務

1、打開mac下自帶軟件“屏幕共享”即可連接(驚歎mac的強大之處,不需要安裝第三方客戶端)

 2、注意連接字符串,其中ml和IP需要替換成你自己的

 

3、連接成功,可以在mac看到ubuntu登陸界面了(比XQuartZ效果好太多太多)

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章