LoginSignup
51
63

More than 5 years have passed since last update.

VPS上のubuntu 18.04 LTSにVNC接続するまで

Last updated at Posted at 2018-11-27

目標

Microsoft AzureやGoogle Cloud Platform、AWSなどのVPS上にあるssh接続しかできない状態のubuntu 18.04 LTSに対して、VNCで接続することでGUIでの操作を可能にする
Kobito.BjLehG.png
(完成イメージ)

VPSへの初回アクセスから初期設定まで

$に続く文字列は入力内容、その他は出力内容
[]内は任意の値を入力([]は入力不要))

初回アクセス

$ ssh [ユーザー名]@[IPアドレス]

Are you sure you want to continue connecting (yes/no)? 

$ yes

ユーザー名@IPアドレス's password:[初期パスワード]

ログイン完了

You are required to change your password immediately (root enforced)
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-1031-azure x86_64)
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

初期パスワードの変更

WARNING: Your password has expired.
You must change your password now and login again!
Changing password for ユーザー名.
(current) UNIX password: [現在のパスワード]
Enter new UNIX password: [新しいパスワード]
Retype new UNIX password: [新しいパスワード]
passwd: password updated successfully
Connection to IPアドレス closed.

再度アクセス

$ ssh [ユーザー名]@[IPアドレス]
ユーザー名@IPアドレス's password:[新しいパスワード]

パッケージを最新に

$ sudo apt-get update
$ sudo apt-get upgrade -y

X Window System(デスクトップ環境)の導入

インストール

$ sudo apt-get install ubuntu-desktop -y

処理には10分近くかかるので待機

ディスプレイマネージャー(gnome)の導入

インストール

$ sudo apt-get install -y gnome-core gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal

VNCサーバ(vnc4server)の導入

インストール

$ sudo apt-get -y install vnc4server

VNCパスワードの登録

$vncpasswd
Password:[パスワード]
Verify:[パスワード]

初期ファイルの生成

$ vncserver :1
$ vncserver -kill :1

xstartupの設定

$ vi ~/.vnc/xstartup

xstartupの初期状態

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession

xstartupの下部に追記

exec gnome-session &
gnome-panel &
gnome-settings-daemon &
metacity &
nautilus -n &
gnome-terminal &

再起動

$ sudo reboot

VNCサーバの起動

ssh接続でポートフォワーディング

$ ssh -L 1234:localhost:5901 [IPアドレス] -l [ユーザー名]
ユーザー名@IPアドレス's password:[パスワード]

vncserverの起動

$ vncserver

vncserverへの接続(Mac編)

前編でのポートフォワーディングが有効な状態でファインダーを開き、⌘+K
vnc://localhost:1234を入力、接続ボタンを押す
Kobito.2txYVg.png
パスワードが要求されるので、VNCパスワードを入力して接続する
Kobito.vxCrQm.png

接続が完了し、ubuntu18.04 LTSのデスクトップが表示される
Kobito.TElxzk.png

51
63
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
51
63