在 Compute Engine 中設定 Linux 適用的 Chrome 遠端桌面

Last reviewed 2025-05-12 UTC

本教學課程示範如何在 Compute Engine 的 Debian Linux 虛擬機器 (VM) 執行個體上設定 Chrome 遠端桌面服務。如需 Windows VM 的個別操作說明,請參閱「Windows 虛擬機器」。Chrome 遠端桌面可讓您透過本機電腦或行動裝置的圖形使用者介面,遠端存取應用程式。

在本教學課程中,預設的防火牆規則會允許 Chrome 遠端桌面連線,因此您不需要設定任何額外的防火牆規則。只有在初始設定時才需要 SSH 存取權。

VM 需要存取網際網路 (使用外部 IP 位址或透過 Cloud NAT),且您必須使用 Google 帳戶進行驗證和授權。

本教學課程假設您熟悉 Linux 指令列及安裝 Debian 套件。

如要瞭解建立虛擬工作站的其他選項,請參閱「建立虛擬工作站」。

目標

  • 建立要用以執行 Chrome 遠端桌面的無介面 Compute Engine VM 執行個體。
  • 在 VM 執行個體上安裝及設定 Chrome 遠端桌面服務。
  • 在 VM 執行個體中設定 X Window System 桌面環境。
  • 從您的本機電腦連線至 VM 執行個體上的桌面環境。

費用

本教學課程使用 Google Cloud的計費元件,包括:

  • Compute Engine

使用 Pricing Calculator 可根據您的預測使用量來產生費用預估。

事前準備

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Compute Engine API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Compute Engine API.

    Enable the API

  8. 完成本文件所述工作後,您可以刪除已建立的資源,避免繼續計費。詳情請參閱「清除所用資源」。

  9. Make sure that you have the following role or roles on the project: roles/compute.admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往「身分與存取權管理」頁面
    2. 選取專案。
    3. 按一下 「授予存取權」
    4. 在「New principals」(新增主體) 欄位中輸入使用者 ID。 通常是 Google 帳戶的電子郵件地址。

    5. 在「請選擇角色」清單中,選取角色。
    6. 如要授予其他角色,請按一下 「Add another role」(新增其他角色),然後新增其他角色。
    7. 按一下 [Save]
    8. 您在本機電腦上使用 Google Chrome 瀏覽器。

建立 Compute Engine 執行個體

為了配合本教學課程的目的,我們會使用含 Debian Linux 開機磁碟的預設機器類型。如果您要將這個環境用於自己的環境,建議您調整機器類型、名稱、區域、啟動磁碟大小或其他設定。

  1. 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面

    前往「VM Instances」(VM 執行個體)

  2. 按一下 [建立]。

  3. 將執行個體名稱設為 crdhost

  4. 按一下 [建立]。

    建立執行個體需要一些時間。

  5. 建立執行個體之後,按一下執行個體清單中的「SSH」SSH連線至新執行個體:

    建立 VM 執行個體的 SSH 連線。

在 VM 執行個體上安裝 Chrome 遠端桌面

  1. 在 VM 執行個體的 SSH 視窗中,將 Debian Linux Chrome 遠端桌面存放區新增至 apt 套件清單,然後安裝 chrome-remote-desktop 套件。

    curl https://dl.google.com/linux/linux_signing_key.pub \
        | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/chrome-remote-desktop.gpg
    echo "deb [arch=amd64] https://dl.google.com/linux/chrome-remote-desktop/deb stable main" \
        | sudo tee /etc/apt/sources.list.d/chrome-remote-desktop.list
    sudo apt-get update
    sudo DEBIAN_FRONTEND=noninteractive \
        apt-get install --assume-yes chrome-remote-desktop
    

    DEBIAN_FRONTEND=noninteractive 參數會略過為直接連線至 VM 執行個體之鍵盤設定配置的提示。

安裝 X Windows System 桌面環境

您需要安裝 X Window System 桌面環境與視窗管理員,才能使用 Chrome 遠端桌面。常用選項如下:

您可以使用其他桌面環境,但是 Chrome 遠端桌面不支援 3D 圖形加速功能。如果您選擇使用 3D 圖形加速功能的桌面環境,則需要停用該功能,否則遠端桌面服務不會啟動。

針對透過較慢網路進行的遠端連線,我們建議使用 Xfce,因為它只有少量圖形元素和動畫。

Xfce

  1. 在連線至 VM 執行個體的「SSH」視窗中,安裝 Xfce 桌面環境與基本桌面元件:

    sudo DEBIAN_FRONTEND=noninteractive \
        apt install --assume-yes xfce4 desktop-base dbus-x11 xscreensaver
    

    由於 Xfce 預設的螢幕鎖定程式 (Light Locker) 無法與 Chrome 遠端桌面搭配使用 (Light Locker 會顯示空白畫面,且無法解鎖),因此必須使用 XScreenSaver

  2. 將 Chrome 遠端桌面設定為預設使用 Xfce:

    sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/xfce4-session" > /etc/chrome-remote-desktop-session'
    
  3. 由於執行個體未連接任何顯示器,請停用執行個體上的顯示器管理員服務:

    sudo systemctl disable lightdm.service
    
  4. 選用:安裝完整的 Linux 桌面應用程式套件,以及 Xfce 桌面環境:

    sudo apt install --assume-yes task-xfce-desktop
    
  5. 選用:在執行個體上安裝 Chrome 瀏覽器:

    curl -L -o google-chrome-stable_current_amd64.deb \
    https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo apt install --assume-yes --fix-broken ./google-chrome-stable_current_amd64.deb
    

Cinnamon

  1. 在連線至 VM 執行個體的「SSH」視窗中,安裝 Cinnamon 桌面環境與基本桌面元件:

    sudo DEBIAN_FRONTEND=noninteractive \
        apt install --assume-yes cinnamon-core desktop-base dbus-x11
    
  2. 將您的 Chrome 遠端桌面工作階段設定為預設會在 2D 模式下使用 Cinnamon (2D 模式的 Cinnamon 不會使用 3D 圖形加速功能):

    sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/cinnamon-session-cinnamon2d" > /etc/chrome-remote-desktop-session'
    
  3. 選用:安裝完整的 Linux 桌面應用程式套件,以及 Cinnamon 桌面環境:

    sudo apt install --assume-yes task-cinnamon-desktop
    
  4. 選用:在執行個體上安裝 Chrome 瀏覽器:

    curl -L -o google-chrome-stable_current_amd64.deb \
    https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo apt install --assume-yes --fix-broken ./google-chrome-stable_current_amd64.deb
    

地精

  1. 在連線至 VM 執行個體的 SSH 視窗中,安裝完整的 Gnome 桌面環境:

    sudo DEBIAN_FRONTEND=noninteractive \
        apt install --assume-yes  task-gnome-desktop
    
  2. 將 Chrome 遠端桌面工作階段設定為使用 Gnome

    sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/gnome-session" > /etc/chrome-remote-desktop-session'
    
  3. 停用執行個體上的 Gnome 顯示器管理員服務,因為該服務與 Chrome 遠端桌面服務發生衝突。

    sudo systemctl disable gdm3.service
    sudo reboot
    

    這個指令會重新啟動 VM。

  4. 請先透過 SSH 重新連線再繼續操作。

  5. 選用:在執行個體上安裝 Chrome 瀏覽器:

    curl -L -o google-chrome-stable_current_amd64.deb \
    https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo apt install --assume-yes --fix-broken ./google-chrome-stable_current_amd64.deb
    

Gnome-Classic

  1. 在連線至 VM 執行個體的 SSH 視窗中,安裝完整的 Gnome 桌面環境:

    sudo DEBIAN_FRONTEND=noninteractive \
        apt install --assume-yes  task-gnome-desktop
    

    DEBIAN_FRONTEND=noninteractive 參數會略過為直接連線至 VM 執行個體之鍵盤設定配置的提示。

  2. 將 Chrome 遠端桌面工作階段設定為使用 Gnome-Classic 桌面:

    sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/gnome-session-classic" > /etc/chrome-remote-desktop-session'
    
  3. 停用執行個體上的 Gnome 顯示器管理員服務,因為該服務與 Chrome 遠端桌面服務發生衝突。

    sudo systemctl disable gdm3.service
    sudo reboot
    

    這個指令會重新啟動 VM。

  4. 請先透過 SSH 重新連線再繼續操作。

  5. 選用:在執行個體上安裝 Chrome 瀏覽器:

    curl -L -o google-chrome-stable_current_amd64.deb \
    https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo apt install --assume-yes --fix-broken ./google-chrome-stable_current_amd64.deb
    

KDE Plasma

  1. 在連線至 VM 執行個體的「SSH」視窗中,安裝完整的 KDE Plasma 桌面環境:

    sudo DEBIAN_FRONTEND=noninteractive \
        apt install --assume-yes  task-kde-desktop
    

    DEBIAN_FRONTEND=noninteractive 參數會略過為直接連線至 VM 執行個體之鍵盤設定配置的提示。

  2. 將 Chrome 遠端桌面工作階段設定為使用 KDE Plasma

    sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/startplasma-x11" > /etc/chrome-remote-desktop-session'
    
  3. 選用:在執行個體上安裝 Chrome 瀏覽器:

    curl -L -o google-chrome-stable_current_amd64.deb \
    https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo apt install --assume-yes --fix-broken ./google-chrome-stable_current_amd64.deb
    

設定及啟動 Chrome 遠端桌面服務

如要啟動遠端桌面伺服器,您需要擁有您欲用以連線至伺服器的 Google 帳戶所需的授權金鑰:

  1. 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面

    前往「VM Instances」(VM 執行個體) 頁面

  2. 按一下「SSH」SSH按鈕,連線至執行個體。

  3. 在您的本機電腦上使用 Chrome 瀏覽器,前往 Chrome 遠端桌面指令列設定頁面:

    https://remotedesktop.google.com/headless

  4. 如果您尚未登入,請使用 Google 帳戶登入。這是將會用於授權遠端存取權的帳戶。

  5. 在「Set up another computer」頁面上,按一下 [Begin]。

  6. 按一下 [授權]。

    您需要允許 Chrome 遠端桌面存取您的帳戶。如果您允許,頁面會顯示類似以下這樣的 Debian Linux 指令列:

    DISPLAY= /opt/google/chrome-remote-desktop/start-host \
        --code="4/xxxxxxxxxxxxxxxxxxxxxxxx" \
        --redirect-url="https://remotedesktop.google.com/_/oauthredirect" \
        --name=$(hostname)
    

    您可以在 VM 執行個體上使用這個指令設定及啟動 Chrome 遠端桌面服務,並使用授權碼將服務連結至 Google 帳戶。

  7. 將指令複製到連線至執行個體的「SSH」視窗,然後執行指令。

  8. 當您看到提示時,請輸入 6 位數的 PIN 碼。這個數字會在您之後連線時用於進一步的授權。

    您可能會看到 No net_fetcherFailed to read 等錯誤。您可以忽略這些錯誤。

  9. 使用下列指令確認服務是否正在執行。

    sudo systemctl status chrome-remote-desktop@$USER
    

    如果服務正在執行中,您會看見包含 active 狀態的輸出:

    chrome-remote-desktop.service - LSB: Chrome Remote Desktop service
        Loaded: loaded (/lib/systemd/system/chrome-remote-desktop@USER.service; enabled; vendor preset: enabled)
        Active: active (running) since DATE_TIME; ELAPSED_TIME
    

連線至 VM 執行個體

您可以使用 Chrome 遠端桌面網頁應用程式連線至 VM 執行個體。

  1. 在本機電腦上,前往 Chrome 遠端桌面網站。

  2. 按一下「存取我的電腦」

  3. 如果您尚未登入 Google,請使用您用於設定 Chrome 遠端桌面服務的 Google 帳戶登入。

    您會在「Remote Devices」清單中看見新的 VM 執行個體 crdhost

  4. 按一下遠端桌面執行個體的名稱。

  5. 系統出現提示時,輸入您之前建立的 PIN 碼,然後按一下箭號按鈕進行連線。

    您現在已連線至遠端 Compute Engine 執行個體上的桌面環境。

  6. 如果系統顯示提示,請一律允許遠端桌面應用程式讀取剪貼簿,並讓您在本機和遠端應用程式之間複製及貼上內容。

  7. 如果您安裝了 Xfce 桌面,當您第一次連線時,系統會提示您設定桌面面板。按一下 [Use Default Config] (使用預設設定) 可在頂部看見標準工作列,並在底部看見快速啟動面板。

顯示工作列與快速啟動面板的 xfce 桌面。

改善遠端桌面體驗

本節提供變更設定的操作說明,可協助您改善遠端桌面體驗。

安裝 Chrome 遠端桌面應用程式

Chrome 遠端桌面應用程式可提供獨立的視窗體驗,並允許在遠端系統上使用 Chrome 通常會攔截的鍵盤快速鍵。

如果未安裝這個應用程式,請按照下列步驟操作:

  1. 將滑鼠移至視窗側邊,然後使用 按鈕開啟「工作階段選項」面板。
  2. 在「安裝應用程式」部分中,按一下「開始」
  3. 按一下 [安裝]

遠端桌面工作階段會在自己的應用程式視窗中重新開啟。

只要在網址列中按一下「Open With」 圖示,即可將任何遠端桌面工作階段從 Chrome 分頁移至應用程式視窗。

停用 Cinnamon 的動畫與效果

Cinnamon 桌面使用數種圖形功能與動畫,例如可以漸入與漸出的半透明視窗和選單。由於這些動畫在遠端連線時需要較長時間顯示,因此會使您感覺使用者介面比較慢。

如要停用這些效果:

  1. 在 Cinnamon 桌面中,選取 [Menu] (選單) > [Preferences] (偏好設定) > [Effects] (特效)

    設定 Cinnamon 的桌面偏好設定。

  2. 停用以下每一種效果:

    停用 Cinnamon 的動畫效果。

設定使用者密碼

Compute Engine 建立的使用者帳戶沒有密碼。不過,部分桌面環境需要使用密碼才能解鎖螢幕保護程式,並授權執行管理操作。因此,為使用者設定密碼非常重要:

  1. 就像您第一次設定執行個體一樣,使用 SSH 連線至執行個體。
  2. 為使用者建立密碼:

    sudo passwd $(whoami)
    

停用螢幕保護程式和鎖定螢幕

由於您會從遠端電腦存取桌面,因此通常不需要使用螢幕保護程式或螢幕鎖定程式,因此您可以停用這類功能。

Xfce

  1. 在「Applications」選單中,依序選取「Settings」>「Screensaver」
  2. 將「Mode」(模式) 設定為 [Disable Screen Saver] (停用螢幕保護程式)

Cinnamon

  1. 在桌面上,依序選取「選單」>「偏好設定」>「螢幕保護程式」
  2. 在「Settings」(設定) 分頁中,將「Delay」(延遲) 設定為「Never」(永不),然後停用下列兩個鎖定設定,即可自動鎖定螢幕。

地精

  1. 在電腦上按一下「活動」,然後輸入 Settings
  2. 選取「設定」應用程式。
  3. 在「設定」應用程式中,依序選取「隱私權」「螢幕鎖定」
  4. 停用「自動螢幕鎖定」並關閉對話方塊。
  5. 依序選取「裝置」>「鍵盤」
  6. 在鍵盤快速鍵清單中,前往「系統」部分,然後按一下「螢幕鎖定」
  7. 按下 Backspace 鍵來停用捷徑,然後點選「設定」
  8. 選取「電源」,然後將「空白畫面」設為「永不」

Gnome-Classic

  1. 在桌面上,依序選取「應用程式」>「系統工具」>「設定」
  2. 在「設定」應用程式中,依序選取「隱私權」「螢幕鎖定」
  3. 停用「自動螢幕鎖定」並關閉對話方塊。
  4. 依序選取「裝置」>「鍵盤」
  5. 在鍵盤快速鍵清單中,前往「系統」部分,然後按一下「螢幕鎖定」
  6. 按下 Backspace 鍵來停用捷徑,然後點選「設定」
  7. 選取「電源」,然後將「空白畫面」設為「永不」

KDE Plasma

  1. 在桌面上,按一下 KDE 選單按鈕,然後輸入 Screen Locking
  2. 選取「Screen Locking」應用程式。
  3. 在「Configure Screen Locking」應用程式中,停用「Lock Screen after」,然後按一下 按鈕,清除鍵盤快捷鍵。
  4. 按一下 [確定]

增加桌面解析度

如果您擁有超高解析度顯示器,可能會發現預設的最大遠端桌面大小 1600 x 1200 太小。若是如此,您可以將該解析度增加到顯示器的解析度。

  1. 使用 SSH 連線至執行個體。
  2. 設定 CHROME_REMOTE_DESKTOP_DEFAULT_DESKTOP_SIZES 環境變數,使其包含顯示器的解析度:

    echo "export CHROME_REMOTE_DESKTOP_DEFAULT_DESKTOP_SIZES=1600x1200,3840x2560" \
        >> ~/.profile
    
  3. 重新啟動服務:

    sudo systemctl restart chrome-remote-desktop@$USER
    

啟用進階影片編解碼器:

採用高品質色彩的 AV1 轉碼器可改善影像品質,並可更妥善地編碼純色資訊 (例如文字):

  1. 將滑鼠移至視窗側邊,然後使用 按鈕開啟「工作階段選項」面板。
  2. 在「Video Codec」欄位中,選取「AV1」
  3. 確認已啟用「高品質色彩」欄位。

選擇不同的桌面環境

在先前的章節中,您在全域 /etc/chrome-remote-desktop-session 設定檔中設定了預設的桌面環境。您也可以藉由指定主目錄中的 .chrome-remote-desktop-session 設定檔,選擇不同的桌面環境 (若已經安裝):

Xfce

echo "exec /etc/X11/Xsession /usr/bin/xfce4-session" > ~/.chrome-remote-desktop-session

Cinnamon

echo "exec /etc/X11/Xsession /usr/bin/cinnamon-session-cinnamon2d" > ~/.chrome-remote-desktop-session

地精

echo "exec /etc/X11/Xsession /usr/bin/gnome-session" > ~/.chrome-remote-desktop-session

Gnome-Classic

echo "exec /etc/X11/Xsession /usr/bin/gnome-session-classic" > ~/.chrome-remote-desktop-session

KDE Plasma

echo "exec /etc/X11/Xsession /usr/bin/startplasma-x11" > ~/.chrome-remote-desktop-session

進行此變更後,請重新啟動服務,讓變更生效:

sudo systemctl restart chrome-remote-desktop@$USER

如前文所述,Chrome 遠端桌面不支援 3D 圖形加速功能。因此,在使用這些功能的任何桌面環境中,您都必須停用 3D 圖形功能,否則工作階段將無法開始。

自動化安裝程序

需要使用 Chrome 遠端桌面設定多部機器時,手動安裝步驟可能會顯得重複性高。您可以利用下列程序,使用自訂開機指令碼自動化此流程:

為了配合本教學課程的目的,我們會使用含 Debian Linux 開機磁碟的預設機器類型。如果您要將這個環境用於自己的環境,建議您調整機器類型、名稱、地區、開機磁碟大小或其他設定。

  1. 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面

    前往「VM Instances」(VM 執行個體) 頁面

  2. 點選「建立執行個體」

  3. 將執行個體名稱設為 crdhost-autoinstall

  4. 捲動至「進階選項」部分並展開。

  5. 展開「管理」部分。

  6. 複製下列殼層指令碼,並將其貼至「Automation/Startup Script」(自動化/開機指令碼) 欄位:

    #!/bin/bash -x
    #
    # Startup script to install Chrome remote desktop and a desktop environment.
    #
    # See environmental variables at then end of the script for configuration
    #
    
    function install_desktop_env {
      PACKAGES="desktop-base xscreensaver dbus-x11"
    
      if [[ "$INSTALL_XFCE" != "yes" && "$INSTALL_CINNAMON" != "yes" ]] ; then
        # neither XFCE nor cinnamon specified; install both
        INSTALL_XFCE=yes
        INSTALL_CINNAMON=yes
      fi
    
      if [[ "$INSTALL_XFCE" = "yes" ]] ; then
        PACKAGES="$PACKAGES xfce4"
        echo "exec xfce4-session" > /etc/chrome-remote-desktop-session
        [[ "$INSTALL_FULL_DESKTOP" = "yes" ]] && \
          PACKAGES="$PACKAGES task-xfce-desktop"
      fi
    
      if [[ "$INSTALL_CINNAMON" = "yes" ]] ; then
        PACKAGES="$PACKAGES cinnamon-core"
        echo "exec cinnamon-session-cinnamon2d" > /etc/chrome-remote-desktop-session
        [[ "$INSTALL_FULL_DESKTOP" = "yes" ]] && \
          PACKAGES="$PACKAGES task-cinnamon-desktop"
      fi
    
      DEBIAN_FRONTEND=noninteractive \
        apt-get install --assume-yes $PACKAGES $EXTRA_PACKAGES
    
      systemctl disable lightdm.service
    }
    
    function download_and_install { # args URL FILENAME
      if [[ -e "$2" ]] ; then
         echo "cannot download $1 to $2 - file exists"
         return 1;
      fi
      curl -L -o "$2" "$1" && \
        apt-get install --assume-yes --fix-broken "$2" && \
        rm "$2"
    }
    
    function is_installed {  # args PACKAGE_NAME
      dpkg-query --list "$1" | grep -q "^ii" 2>/dev/null
      return $?
    }
    
    # Configure the following environmental variables as required:
    INSTALL_XFCE=yes
    INSTALL_CINNAMON=yes
    INSTALL_CHROME=yes
    INSTALL_FULL_DESKTOP=yes
    
    # Any additional packages that should be installed on startup can be added here
    EXTRA_PACKAGES="less bzip2 zip unzip tasksel wget"
    
    apt-get update
    
    if ! is_installed chrome-remote-desktop; then
        if [[ ! -e /etc/apt/sources.list.d/chrome-remote-desktop.list ]]; then
            echo "deb [arch=amd64] https://dl.google.com/linux/chrome-remote-desktop/deb stable main" \
                | tee -a /etc/apt/sources.list.d/chrome-remote-desktop.list
        fi
        apt-get update
        DEBIAN_FRONTEND=noninteractive \
            apt-get install --assume-yes chrome-remote-desktop
    fi
    
    install_desktop_env
    
    [[ "$INSTALL_CHROME" = "yes" ]] && ! is_installed google-chrome-stable && \
      download_and_install \
        https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
        /tmp/google-chrome-stable_current_amd64.deb
    
    echo "Chrome remote desktop installation completed"
    

    此指令碼會在每次機器重新啟動時執行下列工作:

    • 如果未安裝遠端桌面套件:
      • 新增 Chrome 遠端桌面 Debian 套件存放區
      • 安裝 Chrome 遠端桌面套件和依附元件。
    • 安裝 Xfce 或 Cinnamon 桌面環境 (安裝何者視指令碼設定而定)。
    • 如已啟用完整桌面環境選項,則會安裝必要的套件。
    • 如果 Google Chrome 瀏覽器選項已啟用但未安裝:
      • 下載 Google Chrome 套件。
      • 安裝 Google Chrome 及其依附套件。
  7. 按一下 [建立]。

    建立執行個體需要一些時間,且第一次啟用所有選項時,指令碼可能需要多達 10 分鐘的時間才能完成安裝。

  8. 如要監控進度,請使用 SSH 連線到 VM 執行個體,並在執行個體的終端機中執行下列指令:

    sudo journalctl -o cat -f _SYSTEMD_UNIT=google-startup-scripts.service
    

    此指令會顯示來自開機指令碼的輸出。指令碼完成後,您會看到以下內容:

    INFO startup-script: Chrome remote desktop installation completed
    INFO startup-script: Return code 0.
    INFO Finished running startup scripts.
    

此指令碼只會安裝必要的套件,而您仍需要為使用者設定「遠端桌面服務」,如前文所述。

建立新的 VM 執行個體時,有多種方法可以指定開機指令碼:

  • 將指令碼貼至 Google Cloud 主控台 (如前文所示)。
  • 以檔案的方式儲存在本機,並在透過 Google Cloud CLI 建立執行個體時,使用 --metadata-from-file 標記。
  • 將指令碼儲存到 Cloud Storage 值區中,並在主控台或 gcloud CLI 中指定物件的網址。

如要進一步瞭解設定開機指令碼的其他方法,請參閱 Compute Engine 說明文件中的執行開機指令碼一文。

疑難排解

本節提供本指南的疑難排解建議。

檢查 Chrome 遠端桌面服務的狀態

如果發生 Chrome 遠端桌面服務沒有回應的情形,您可以使用 SSH 連線至執行個體並執行下列指令來檢查其狀態:

sudo systemctl status chrome-remote-desktop@$USER

如果服務正在執行中,您會看見包含 active 狀態的輸出:

chrome-remote-desktop.service - LSB: Chrome Remote Desktop service
    Loaded: loaded (/lib/systemd/system/chrome-remote-desktop@USER.service; enabled; vendor preset: enabled)
    Active: active (running) since DATE_TIME; ELAPSED_TIME

如要重新啟動服務,請在「SSH」視窗中執行下列指令:

sudo systemctl restart chrome-remote-desktop@$USER

取得記錄與錯誤資訊

Chrome 遠端桌面會將記錄資訊寫入系統日誌:

journalctl SYSLOG_IDENTIFIER=chrome-remote-desktop     # All logs
journalctl SYSLOG_IDENTIFIER=chrome-remote-desktop -e  # Most recent logs
journalctl SYSLOG_IDENTIFIER=chrome-remote-desktop -b  # Logs since reboot

您可以檢查這些記錄檔中的錯誤訊息。

重新啟用服務

如果您在用戶端應用程式中錯誤地停用了遠端執行個體的連線,可以重新設定服務並按照「設定及啟動 Chrome 遠端桌面服務」的操作說明重新啟用連線。

檢查全域和使用者專屬的工作階段設定檔。

檢查全域 /etc/chrome-remote-desktop-session 設定檔和特定使用者 ~/.chrome-remote-desktop-session 設定檔的內容,確認已安裝指定的桌面環境。

清除所用資源

如要避免系統向您的 Google Cloud 帳戶收取本教學課程中所用資源的相關費用,請刪除含有該項資源的專案,或者保留專案但刪除個別資源。

刪除專案

如要避免付費,最簡單的方法就是刪除您為了本教學課程所建立的專案。

如要刪除專案:

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

刪除 Compute Engine 執行個體

您不必刪除完整專案,而是可以刪除針對本教學課程建立的 VM 執行個體:

  1. 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面

    前往「VM Instances」(VM 執行個體) 頁面

  2. 找出您之前建立的執行個體名稱 (crdhost),並選取旁邊的核取方塊。

  3. 點選頁面頂端的 [Delete] (刪除) 按鈕。

    刪除 VM 執行個體。

    刪除執行個體需要一些時間。

取消執行個體的 Chrome 遠端桌面授權

如果您不想再連線至 VM 執行個體,可以將其停用,並從「Remote Devices」清單中移除該執行個體。

  1. 在本機電腦上,前往 Chrome 遠端桌面遠端裝置清單網站。
  2. 按一下執行個體名稱 crdhost 旁的
  3. 按一下 [OK] 以確認停用該遠端裝置連線。

後續步驟