Spot CORE VNC

前言大綱

VNC 允許用戶在遠程機器上啟動圖形應用程序並與之交互。

本文檔詳細介紹瞭如何在 Spot CORE 上設置 TigerVNC。 我們還將在下面的內容中使用 GNOME 桌面環境、端口轉發 port forwarding 和 systemd ,service files。

概述

Spot CORE 現在預配置了 TigerVNC。 以下部分概述了在使用前啟用服務所需的步驟。

如果 Spot CORE 位於高於 2.0.1 的任何軟件版本上,則不需要。

TigerVNC 服務器啟用

首先,訪問 Spot CORE 上的終端。 為此,您可以通過 https://192.168.80.3:21443 登錄 Cockpit 並轉到 Terminal tab,或者您可以通過命令行連接:

ssh -p 20022 spot@192.168.80.3

創建 VNC 密碼

將為您創建一個默認密碼“password”。 此密碼用於從客戶端訪問 VNC 會話,之後您需要使用 Spot CORE 的標準用戶名和密碼登錄。 您還可以選擇使用以下命令創建新的 VNC 密碼(不需要僅查看密碼):

vncpasswd

在所需端口上啟用並啟動服務。

sudo systemctl enable vncserver@15100 # Enable service with the desired port.
sudo systemctl start vncserver@15100  # Start service.
systemctl status vncserver@15100 # Check the service is running.
在上面的示例命令中,使用的 vncserver 端口號是 21000 (5900 + 15100)。 有關更多信息,請參閱 : start vncserver

TigerVNC 查看器

在 PC 上執行以下步驟以啟動 VNC 連接。

安裝 vncviewer

通過從 https://bintray.com/tigervnc/stable/tigervnc/ 下載 vncviewer64-1.10.1.exe 安裝適用於 64 位 Windows 的 vncviewer。

使用apt在Ubuntu上安裝tigervnc-viewer:

sudo apt install tigervnc-viewer

啟動 vncviewer

我們需要首先使用 SSH 通道 創建安全連接。 以下命令假設用戶已連接到 Spot 的接入點。 如果需要,不要忘記更改 IP 地址或端口號。 要在後台運行此 ssh session  而不執行任何命令,請在命令末尾添加 -fN 參數。

ssh -4 -p 20022 spot@192.168.80.3 -L 21000:127.0.0.1:21000

啟動 VNC Viewer 並傳遞 IP 地址和端口號。

vncviewer localhost:21000

輸入之前使用 vncpasswd 設置的密碼後,現在應該可以使用 GNOME 桌面環境。

TigerVNC 服務器安裝

如果 Spot CORE 位於大於或等於 2.3.0 的任何軟件版本上,則不需要此部分。

安裝軟件

使用 apt 在 Spot CORE 上安裝 TigerVNC 服務器所需的軟件:

sudo apt install tigervnc-standalone-server tigervnc-common tigervnc-xorg-extension tigervnc-viewer

如果用戶尚未設置 VNC 密碼,請參閱之前有關如何  創建 vnc 密碼  create a vnc password 的說明。

準備 vncserver

要配置 GNOME 桌面,請在 ~/.vnc/xstartup 中創建一個 xstartup 文件並添加以下內容。

#!/bin/sh
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &

要為遠程會話(例如 VNC)啟用編輯某些系統設置的權限,請在 /etc/polkit-1/localauthority/50-local.d/ 中創建以下文件:

10-network-manager.pkla

[Let user spot modify system settings for network]
Identity=unix-user:spot
Action=org.freedesktop.NetworkManager.*
ResultAny=auth_admin_keep
ResultInactive=no
ResultActive=yes

46-user-admin.pkla

[control center administration]
Identity=unix-user:*
Action=org.gnome.controlcenter.*
ResultAny=auth_admin_keep
ResultInactive=no
ResultActive=yes

啟動 vncserver

TigerVNC 偵聽端口 5900+。 默認端口為 5901 (5900 + 1),可以使用以下命令啟動。

vncserver :1

為了指定一個不同的端口,比如 21000,運行 vncserver,編號等於 21000 - 5900 = 15100

vncserver :15100

使用 -list 查看之前啟動的 vnc 服務器。

vncserver -list

使用以下命令停止之前啟動的 vnc 服務器。

vncserver -kill :1
vncserver -kill :15100

在啟動時啟用 vncserver

為了讓 vncserver 在 Spot 開啟時自動在 Spot CORE 上運行,請使用 systemd .service 文件。 創建一個名為 vncserver@.service 的服務文件並添加以下內容。 該文件可以將端口號作為參數。

[Unit]
Description=TigerVNC server
After=network.target

[Service]
Type=simple
RemainAfterExit=yes
SuccessExitStatus=0

PIDFile=/home/spot/.vnc/%H:%i.pid
ExecStartPre=/bin/su -l spot -c "/usr/bin/vncserver -kill :%i > /dev/null"
ExecStart=/bin/su -l spot -c "/usr/bin/vncserver :%i -localhost no"
ExecStop=/bin/su -l spot -c "/usr/bin/vncserver -kill :%i"

[Install]
WantedBy=multi-user.target

將文件複製到 /etc/systemd/system/ 並啟動服務。根據需要更改端口號。

sudo cp vncserver@.service /etc/systemd/system/ 
sudo systemctl daemon-reload # Reloads all systemd services.

有用的 TigerVNC 資源


參考資料

特色、摘要,Feature、Summary:

關鍵字、標籤,Keyword、Tag:

留言

這個網誌中的熱門文章

Ubuntu 常用指令、分類與簡介

iptables的觀念與使用

網路設定必要參數IP、netmask(遮罩)、Gateway(閘道)、DNS

了解、分析登錄檔 - log

Python 與SQLite 資料庫

Blogger文章排版範本

Pandas 模組

如何撰寫Shell Script

查詢指令或設定 -Linux 線上手冊 - man

下載網頁使用 requests 模組