What's?
Rocky Linux 9にVNCサーバを導入します。
導入するVNCサーバはTigerVNCで、systemdとしてサービス登録まで行うところを目指します。
環境
今回の環境はこちら。
$ cat /etc/redhat-release
Rocky Linux release 9.7 (Blue Onyx)
$ uname -srvmpio
Linux 5.14.0-611.16.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Dec 22 12:21:56 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
また日本語化、デスクトップ環境の導入までは済ませているものとします。
$ sudo dnf install -y glibc-langpack-ja
$ sudo localectl set-locale LANG=ja_JP.utf8
$ sudo localectl set-keymap jp106
$ sudo timedatectl set-timezone Asia/Tokyo
$ sudo dnf install -y langpacks-ja
$ sudo dnf group install 'Server with GUI'
VNCサーバをインストールする
今回はTigerVNCサーバをインストールします。パッケージの情報はこちら。
$ dnf info tigervnc-server
メタデータの期限切れの最終確認: 0:00:02 前の 2026年01月01日 14時40分45秒 に実施しました。
利用可能なパッケージ
名前 : tigervnc-server
バージョン : 1.15.0
リリース : 6.el9_7
Arch : x86_64
サイズ : 262 k
ソース : tigervnc-1.15.0-6.el9_7.src.rpm
リポジトリー : appstream
概要 : A TigerVNC server
URL : http://www.tigervnc.com
ライセンス : GPL-2.0-or-later
説明 : The VNC system allows you to access the same desktop from a wide
: variety of platforms. This package includes set of utilities
: which make usage of TigerVNC server more user friendly. It also
: contains x0vncserver program which can export your active
: X session.
インストール。
$ sudo dnf install tigervnc-server
systemdの設定ファイルも含まれるようです。
$ rpm -ql tigervnc-server
/etc/pam.d/tigervnc
/etc/tigervnc/vncserver-config-defaults
/etc/tigervnc/vncserver-config-mandatory
/etc/tigervnc/vncserver.users
/usr/bin/vncserver
/usr/bin/x0vncserver
/usr/lib/.build-id
/usr/lib/.build-id/21
/usr/lib/.build-id/21/e15c4ce80097f1b0bc368bdf561a6f859caf0b
/usr/lib/.build-id/6a
/usr/lib/.build-id/6a/d1f1be15af98427a3c457ded279db0a267fb20
/usr/lib/systemd/system/vncserver@.service
/usr/lib/systemd/system/xvnc.socket
/usr/lib/systemd/system/xvnc@.service
/usr/libexec/vncserver
/usr/libexec/vncsession-restore
/usr/libexec/vncsession-start
/usr/sbin/vncsession
/usr/share/doc/tigervnc/HOWTO.md
/usr/share/man/man1/x0vncserver.1.gz
/usr/share/man/man8/vncserver.8.gz
/usr/share/man/man8/vncsession.8.gz
起動はしていませんが。
$ sudo systemctl status vncserver@1
○ vncserver@1.service - Remote desktop service (VNC)
Loaded: loaded (/usr/lib/systemd/system/vncserver@.service; disabled; preset: disabled)
Active: inactive (dead)
設定ファイルの内容を見てみます。
# The vncserver service unit file
#
# Quick HowTo:
# 1. Add a user mapping to /etc/tigervnc/vncserver.users.
# 2. Adjust the global or user configuration. See the
# vncsession(8) manpage for details. (OPTIONAL)
# 3. Run `systemctl enable vncserver@:<display>.service`
# 4. Run `systemctl start 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=network.target systemd-user-sessions.service
[Service]
Type=forking
ExecStartPre=+/usr/libexec/vncsession-restore %i
ExecStart=/usr/libexec/vncsession-start %i
PIDFile=/run/vncsession-%i.pid
SELinuxContext=system_u:system_r:vnc_session_t:s0
[Install]
WantedBy=multi-user.target
よく見ると設定方法が書かれていますね。
# The vncserver service unit file
#
# Quick HowTo:
# 1. Add a user mapping to /etc/tigervnc/vncserver.users.
# 2. Adjust the global or user configuration. See the
# vncsession(8) manpage for details. (OPTIONAL)
# 3. Run `systemctl enable vncserver@:<display>.service`
# 4. Run `systemctl start 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.
/etc/tigervnc/vncserver.usersに:[ディスプレイ]=[ユーザ名]でマッピングを追加します。
# TigerVNC user assignment
#
# This file assigns users to specific VNC display numbers.
# The syntax is <display>=<username>. E.g.:
#
# :2=andrew
# :3=lisa
:1=user
TigerVNCサーバの有効化と起動。
$ sudo systemctl enable vncserver@:1
$ sudo systemctl start vncserver@:1
firewalldは今回は止めておきましょう。
$ sudo systemctl stop firewalld
$ sudo systemctl disable firewalld
あとはマッピングしたユーザのvncpasswdを設定しておきます。
$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
A view-only password is not used
あとはVNCクライアントから5901ポートで接続すればつながるでしょう。接続時にはvncpasswdで設定したパスワードを入力します。
日本語入力をしたい場合は、ibus-mozcをインストールします。
$ sudo dnf install ibus-mozc
再起動(デスクトップセッションの再ログインでいい気がしますが…)すると、設定 → Keyboard → 入力ソースの「+」から日本語 (Mozc)が選べるようになっているので追加しましょう。
完全に反映させたい場合は、やはり再起動(やっぱりデスクトップセッションの再ログインでいい気がしますが…)しましょう。

