【筆記】在GCP上建立可Remote dekstop的Ubuntu環境

Hui Qin Ng
4 min readSep 27, 2018

--

前言

前陣子有人請我幫忙搞一個可以讓人遠端的GCP伺服器,主要是希望有desktop的畫面,方便非工程師背景的人操作 AI 的 training。花了一些時間研究和測試,確定可行後變在此將建立的過程記錄。

環境

GCP Server — Ubuntu 16.04

My Laptop — macOS

1. 升級系統

ssh連線到系統後,先進行更新及升級的動作。

sudo apt-get update && sudo apt-get upgrade

2. 安裝 dependency

升級完成後,再來是安裝VNC Server所需的一些Dependency,如:ubuntu-desktop, gnome-panel 等等

sudo apt-get install ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal

3. 安裝 VNC Server

sudo apt-get install vnc4server

安裝完成後先執行vncserver,會先跳出password設定的選項:

設定password

4. 設定vnc config

修改~/.vnc/xstartup 的設定,加入下面4行

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &

殺掉目前執行的vncserver 然後重新執行:

vncserver -kill :1

vncserver預設是執行在port 5900上,如果在後面加上:1 就是5901以此類推

vncserver :1

5. VNC連線

如果是macOS用戶可推薦您使用 RealVNC Viewer

輸入您機器的IP後面加上port number

連線完成後,會顯示此連線是沒有經過加密的:

警告視窗,繼續的話請選continue
會跳出輸入密碼視窗
進去後就是一個desktop的畫面

6. 設定reboot的時候自動執行vncserver

選擇您想要使用的編輯器

插入reboot資訊於最下方

@reboot /usr/bin/vncserver :1
編輯完後儲存並重啓伺服器測試

Reference

Linode Install VNC on Ubuntu 16.04

--

--

Hui Qin Ng

Major in iOS development, new to Flutter. Welcome to correct anything wrong inside my articles.