CentOS Stream 9  VNC サーバーをインストールする方法

環境
CentOS Stream 9

概要
VNC サーバーをインストールして、クライアント PC からグラフィカルにリモート接続できるようにします。

操作方法
1.VNC サーバーをインストールします。
# dnf -y install tigervnc-server

2. Firewalld を有効にしている場合は、VNC サービスを許可します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# firewall-cmd --add-service=vnc-server
# firewall-cmd --runtime-to-permanent
# firewall-cmd --add-service=vnc-server # firewall-cmd --runtime-to-permanent
# firewall-cmd --add-service=vnc-server
# firewall-cmd --runtime-to-permanent

3. SELinux を有効にしている場合は、ポリシーを変更します
# vi vncsession.te

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 以下の内容で新規作成
module vncsession 1.0;
require {
type default_t;
type xdm_home_t;
type vnc_session_t;
class dir { add_name create write };
class file { create open write };
}
#============= vnc_session_t ==============
allow vnc_session_t default_t:dir { add_name write };
allow vnc_session_t default_t:file { create open write };
allow vnc_session_t xdm_home_t:dir create;
# 以下の内容で新規作成 module vncsession 1.0; require { type default_t; type xdm_home_t; type vnc_session_t; class dir { add_name create write }; class file { create open write }; } #============= vnc_session_t ============== allow vnc_session_t default_t:dir { add_name write }; allow vnc_session_t default_t:file { create open write }; allow vnc_session_t xdm_home_t:dir create;
# 以下の内容で新規作成
module vncsession 1.0;

require {
        type default_t;
        type xdm_home_t;
        type vnc_session_t;
        class dir { add_name create write };
        class file { create open write };
}

#============= vnc_session_t ==============
allow vnc_session_t default_t:dir { add_name write };
allow vnc_session_t default_t:file { create open write };
allow vnc_session_t xdm_home_t:dir create;

モジュールをチェックします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# checkmodule -m -M -o vncsession.mod vncsession.te
# checkmodule -m -M -o vncsession.mod vncsession.te
# checkmodule -m -M -o vncsession.mod vncsession.te

設定を反映します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# semodule_package --outfile vncsession.pp --module vncsession.mod
# semodule -i vncsession.pp
# semodule_package --outfile vncsession.pp --module vncsession.mod # semodule -i vncsession.pp
# semodule_package --outfile vncsession.pp --module vncsession.mod
# semodule -i vncsession.pp

4.Tigervnc を Systemd Unit で起動する場合は以下のように設定します。
事前に、各ユーザー自身で VNC 環境の設定をして、Systemd サービス自体は root 権限で起動します。

VNC パスワードを設定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
s
$ vi ~/.vnc/config
# 新規作成
# session=(使用するディスプレイマネージャー)
# securitytypes=(セキュリティオプション)
# geometry=(画面のサイズ)
session=gnome
securitytypes=vncauth,tlsvnc
geometry=800x600
$vncpasswd Password: Verify: Would you like to enter a view-only password (y/n)? n s $ vi ~/.vnc/config # 新規作成 # session=(使用するディスプレイマネージャー) # securitytypes=(セキュリティオプション) # geometry=(画面のサイズ) session=gnome securitytypes=vncauth,tlsvnc geometry=800x600
$vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
s
$ vi ~/.vnc/config
# 新規作成
# session=(使用するディスプレイマネージャー)
# securitytypes=(セキュリティオプション)
# geometry=(画面のサイズ)
session=gnome
securitytypes=vncauth,tlsvnc
geometry=800x600

5.root 権限で VNC を利用する (ディスプレイ番号)=(ユーザー名) を定義して、Systemd Unit を起動します。
# vi /etc/tigervnc/vncserver.users

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
最終行に追記
# ディスプレイ番号 1 は 5901 番ポートをリスンする
# ディスプレイ番号 n + 5900 = リスンするポート
# ex : ディスプレイ番号 7 + 5900 = 5907 番ポートをリスン
#
# This file assigns users to specific VNC display numbers.
# The syntax is <display>=<username>. E.g.:
#
# :2=andrew
# :3=lisa
:1=cent
:2=redhat
最終行に追記 # ディスプレイ番号 1 は 5901 番ポートをリスンする # ディスプレイ番号 n + 5900 = リスンするポート # ex : ディスプレイ番号 7 + 5900 = 5907 番ポートをリスン # # This file assigns users to specific VNC display numbers. # The syntax is <display>=<username>. E.g.: # # :2=andrew # :3=lisa :1=cent :2=redhat
 最終行に追記
# ディスプレイ番号 1 は 5901 番ポートをリスンする
# ディスプレイ番号 n + 5900 = リスンするポート
# ex : ディスプレイ番号 7 + 5900 = 5907 番ポートをリスン
#
# This file assigns users to specific VNC display numbers.
# The syntax is <display>=<username>. E.g.:
#
# :2=andrew
# :3=lisa
:1=cent
:2=redhat

# 設定したディスプレイ番号分起動する

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl enable --now vncserver@:1 vncserver@:2
# systemctl enable --now vncserver@:1 vncserver@:2
# systemctl enable --now vncserver@:1 vncserver@:2

 

CentOS Stream 9

Posted by arkgame