CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール)

CentOS 7でVNCServerをインストールします。

手順

インストール

rootにて下記のコマンドを実行します。

yum install tigervnc-server

CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像1

パッケージの依存確認処理が始まります。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像2

確認後、インストールを実行するかの確認があります。[y]キーを入力してインストールを続行します。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像3

インストールが完了すると下図の画面が表示されます。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像4

設定ファイルの準備

過去のコマンドを実行し、設定ファイルを複製します。

cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:3.service

/lib/systemd/system/ ディレクトリに内になる、"vncserver@.service"ファイルを "vncserver@:(ディスプレイ番号).service"ファイル名で複製します。ディスプレイ番号は任意の整数でよいですが、"1"は利用されている可能性もあるため、今回は"3"としました。

CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像5

/lib/systemd/system/vncserver@:3.service を編集します。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像6

"<USER>" の部分をVNCでログインするユーザー名(今回の場合は"penta")に変更します。

変更前

# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 2. Edit <USER> and vncserver parameters appropriately
#   ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel.  See the "-via" option in the
# `man vncviewer' manual page.


[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

変更後

# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@.service
# 2. Edit <USER> and vncserver parameters appropriately
#   ("runuser -l <USER> -c /usr/bin/vncserver %i -arg1 -arg2")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, you should
# limit connections to the local host and then tunnel from
# the machine you want to view VNC on (host A) to the machine
# whose VNC output you want to view (host B)
#
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
#
# this will open a connection on port 590N of your hostA to hostB's port 590M
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
# See the ssh man page for details on port forwarding)
#
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
# the help of ssh, you end up seeing what hostB makes available on port 590M
#
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
#
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel.  See the "-via" option in the
# `man vncviewer' manual page.


[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/sbin/runuser -l penta -c "/usr/bin/vncserver %i"
PIDFile=/home/penta/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

vncのパスワードの作成

vncのパスワードを作成します。先の設定ファイルで指定したユーザーで、vncpasswd コマンドを実行します。

su penta
vncpasswd


CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像7

パスワードプロンプトが表示されますので、VNC接続用のパスワードを設定します。Verifyプロンプトが表示されますので、もう一度パスワードを入力します。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像8

vncserverの起動

下記のコマンドを実行し、vncserverを起動します。

systemctl start vncserver@:3

vncserver@:3 の部分は "vncserver@:(ディスプレイ番号)"になります。設定ファイルを複製した名前と同じ番号を指定します。

CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像9

起動できると、何も表示されずコマンドプロンプトに戻ります。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像10

下記のコマンドを実行して、起動状態を確認します。

systemctl status vncserver@:3


状態が "active (running)"となっており、起動状態であることが確認できます。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像11

ファイアウォールの設定

vncserverのファイアウォールの開放をします。ファイアウォールの設定ウィンドウを開きます。上部の設定コンボボックスを開き[永続]を選択します。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像12

左側の[ゾーン]の"public"を選択し、右側のタブの[サービス]を選択します。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像13

右側のサービス一覧から"vnc-server"のチェックボックスをクリックし、チェックをつけます。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像14

設定完了後、[オプション]メニューの[Firewalldの再読み込み]メニューをクリックします。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像15

接続

クライアントPCから接続します。VNC Viewer を起動します。下図の接続ダイアログが表示されます。接続先のホスト名またはIPアドレスとディスプレイ番号を入力します。

(IPアドレス):(ディスプレイ番号)
(ホスト名):(ディスプレイ番号)

CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像16

接続時に下図の暗号化されていない旨のワーニングダイアログが表示されます。[Continue]ボタンをクリックして続行します。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像17

下図の認証ダイアログが表示されます。vncpasswd コマンドで設定したVNC接続用のパスワードを入力します。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像18

初回接続時は、プロファイル作成のための認証画面が表示されることがあります。rootのパスワードを入力し、プロファイルなどを作成します。

接続できると、デスクトップ画面が表示されます。
CentOS 7 でのVNCServerのインストールと設定 (TigerVNC Serverのインストール):画像19

vncserverの自動起動設定

接続動作の確認ができましたら、必要に応じで、vncserverの自動起動設定をします。
自動起動させる場合は

vncserver enable vncserver@:3

コマンドを実行します。

AuthorPortraitAlt
著者
かつて日本を代表したスーパーエンジニア (自称)
ハードウェア、電気設備、ガーデニング関係の記事を担当。
作成日: 2016-04-14
Copyright © 1995–2025 iPentec all rights reserverd.