投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2019年10月30日水曜日

【Raspbian Buster September 2019】VNC Serverを利用してpiユーザーのリモートデスクトップ環境を構築する




■realvnc-vnc-serverというパッケージがインストールされているか確認

○まず、正式なパッケージ名を取得

piユーザーでSSHログインした後、suでrootユーザーになった。

root@raspberrypi:/home/pi# apt-cache search realvnc*
libnet-vnc-perl - Perl module implementing a simple VNC client
realvnc-vnc-server - VNC® Server
realvnc-vnc-viewer - VNC® Viewer

○取得したパッケージ名でインストール操作
すると、既に最新版がインストール済みだとわかった。
root@raspberrypi:/home/pi# apt-get install realvnc-vnc-server
Reading package lists... Done
Building dependency tree     
Reading state information... Done
realvnc-vnc-server is already the newest version (6.5.0.41824).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Raspbian Buster September 2019 with desktop and recommended software には、最初から、realvnc-vnc-serverパッケージがインストールされているとわかった。



■piユーザーでVNCセッションにログインするための設定

ただし、vncserverには三つのモードが存在する。
  -user       Set the password for VNC Server in User Mode.
  -service    Set the password for VNC Server in Service Mode.
  -virtual    Set the password for VNC Server in Virtual Mode.
今回は、VNC ServerをVirtualモードで使いたい。


○まず、piユーザー用に、VNCパスワードを設定した。

piユーザーになった。
root@raspberrypi:/home/pi# su pi

piユーザーのためのVNCパスワードを設定した。(-virtualを指定した。)
pi@raspberrypi:~ $ vncpasswd -virtual
Setting "Password" VNC parameter for Virtual Mode server
Password:
Verify:
Successfully set "Password" VNC parameter in /home/pi/.vnc/config.d/Xvnc
Successfully set "Password" VNC parameter in
/home/pi/.vnc/config.d/vncserver-x11-virtual

○VNCセッションでのマウスカーソルの形状を矢印に設定した。

sudoか、rootユーザーで編集を行うこと。

この設定がなければ、×印のカーソルになった。

CTRL + w で、下記コマンドで設定ファイルを開き、xsetroot を検索して編集箇所を見つけること。

nano /etc/vnc/xstartup
(略)
xsetroot -solid grey -cursor_name left_ptr(略)

CTRL+s で上書き保存、CTRL+x で終了する。


○一度だけ、VNC Serverをpiユーザーで起動した。

piユーザーになった。
root@raspberrypi:/home/pi# su pi

そして、オプションを指定して、VNC Serverを起動した。
(重要)
ここで一度起動しておかないと、必要な設定が自動的にされないようである。また、後の手順に示すように、セッションを終了させることを忘れないように!
オプション最後の、:2はディスプレイ番号である。VNCセッション毎に異なる番号をつける必要がある。
pi@raspberrypi:~ $ /usr/bin/vncserver -Encryption PreferOff -Authentication VncAuth -geometry 1600x900 :2
VNC(R) Server 6.5.0 (r41824) ARMv6 (Aug 16 2019 00:24:44)
Copyright (C) 2002-2019 RealVNC Ltd.
RealVNC and VNC are trademarks of RealVNC Ltd and are protected by trademark
registrations and/or pending trademark applications in the European Union,
United States of America and other jurisdictions.
Protected by UK patent 2481870; US patent 8760366; EU patent 2652951.
See https://www.realvnc.com for information on VNC.
For third party acknowledgements see:
https://www.realvnc.com/docs/6/foss.html
OS: Raspbian GNU/Linux 10, Linux 4.19.75, armv7l
Generating private key... done
On some distributions (in particular Red Hat), you may get a better experience
by running vncserver-virtual in conjunction with the system Xorg server, rather
than the old version built-in to Xvnc. More desktop environments and
applications will likely be compatible. For more information on this alternative
implementation, please see: https://www.realvnc.com/doclink/kb-546
Running applications in /etc/vnc/xstartup
VNC Server catchphrase: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
             signature: xx-xx-xx-xx-xx-xx-xx-xx
Log file is /home/pi/.vnc/raspberrypi:2.log
New desktop is raspberrypi:2 (192.168.1.2:2)

ここで、一度、VNCクライアントソフト(私はTiger VNC Viewerを用いた)から、VNCセッションに接続した。
Raspberry piのIPアドレス:ディスプレイ番号 という書式で、VNC Serverを指定した。
192.168.1.2:2
問題なく、VNCセッションに接続することができた。

★VNCセッションを終了した。(これも忘れないこと!)
pi@raspberrypi:~ $ /usr/bin/vncserver -kill :2



○次に、piユーザーのためのVNC Serverを自動起動するための設定を行った。

(注意)
以下では、systemdを用いてvnc Serverを起動させる設定を行っている。
しかし、systemdからVNC Serverを動作させた場合、polkitが動作しなかった。
そのため、gnome-disksなど特権を必要とするアプリケーションでは権限がないというエラー
「Not authorized to perform operation (udisks-error-quark, 4)」
が表示された。
しかし、上記のように、ユーザーのSSHコンソールからvncserverコマンドを起動する方法では問題は発生しなかった。(←これは重要な回避策
tigervncではこれについてバグが報告されている。
realvncでも同様のバグがあるのではないか。 

rootユーザーになった。
pi@raspberrypi:~ $ su

次のファイルを新規作成して下記のように記述した。
root@raspberrypi:/home/pi# nano /usr/lib/systemd/system/vncserver-pi.service
[Unit]
Description=VNC Server for user pi in Virtual Mode daemon
After=network.target

[Service]
User=pi     
Type=forking
#ExecStart=/usr/bin/vncserver -geometry 1600x900 :2
ExecStart=
/usr/bin/vncserver -Encryption PreferOff -Authentication VncAuth -geometry 1600x900 :2
ExecStop=/usr/bin/vncserver -kill :2
Restart=on-failure
RestartSec=5
KillMode=process

[Install]
WantedBy=multi-user.target

CTRL+s で上書き保存、CTRL+x で終了する。

piユーザーのためのVNC Serverがシステム起動時に自動的に立ち上がるよう設定した。
root@raspberrypi:/home/pi# systemctl enable vncserver-pi.service
Created symlink /etc/systemd/system/multi-user.target.wants/vncserver-pi.service → /usr/lib/systemd/system/vncserver-pi.service.

手動で、VNC Serverを起動した。
root@raspberrypi:/home/pi# systemctl daemon-reload
root@raspberrypi:/home/pi# systemctl start vncserver-pi.service

先程と同様にしてVNCクライアントソフトから、VNCセッションに接続した。
Raspberry piのIPアドレス:ディスプレイ番号 という書式で、VNC Serverを指定した。
192.168.1.2:2
VNCセッションに接続することができた。

手動で、VNC Serverを終了した。
セッション内デスクトップで動作中のプログラムなどは終了するので注意すること!
root@raspberrypi:/home/pi# systemctl stop vncserver-pi.service


これで、システムが再起動すると、自動的に、piユーザーのためのVNC Serverが起動することになる。



○さらに別のユーザーについても同じことを行いたい場合

もし、さらに別のユーザーを追加し各々デスクトップを用意してVNCで接続できるようにしたいなら、次のページを参考にしてください。

【Raspbian Buster September 2019】VNC Server virtualモードで、新規に作成したユーザーのリモートデスクトップ環境を個々に構築する




<参考>

・VNC viewer: "No matching security types"
< https://www.raspberrypi.org/forums/viewtopic.php?t=176408 > 2019年10月25日

・RealVNC server in virtual mode - Enterprise license required?
< https://www.raspberrypi.org/forums/viewtopic.php?t=249124 > 2019年10月25日

・Bug 1633805 - tigervnc-server, when started via systemd produces problems with polokit when DE is Xfce
< https://bugzilla.redhat.com/show_bug.cgi?id=1633805 > 2019年10月25日

・PolicyKit failed over headless VNC
< https://forums.fedoraforum.org/showthread.php?316905-PolicyKit-failed-over-headless-VNC&p=1809280#post1809280 > 2019年10月25日

・Jessie and XRDP
< https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=122386&p=861126 > 2019年10月26日

・Understanding VNC Server Modes
< https://help.realvnc.com/hc/en-us/articles/360002253238-Understanding-VNC-Server-Modes > 2019年10月25日

・VNC Connect and Raspberry Pi
< https://help.realvnc.com/hc/en-us/articles/360002249917-VNC-Connect-and-Raspberry-Pi#creating-and-remoting-a-virtual-desktop-0-5 > 2019年10月25日


投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad