1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ubuntu 20.04(Raspberry Pi 4)のVNC接続メモ

Last updated at Posted at 2023-07-17

初期環境構築メモです。Windows PCからリモートアクセス可能な環境構築のメモです。

※ 追記
完全にリモートで使う場合のメモです。
ディスプレイに接続する場合、この設定のままでは仮想ディスプレイを優先して検出するため、設定を元に戻す必要があります。
もっと簡単な切替手順があれば追記します。


以下のページを参考にさせていただきました。ありがとうございます!

バージョン確認

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.4 LTS
Release:	20.04
Codename:	focal

SSH接続

SSHできている前提です。画面が繋がらなくてもSSH接続できていればなんとかなる安心感があります。

現在のXディスプレイマネージャ確認

$ systemctl status display-manager
● lightdm.service - Light Display Manager
     Loaded: loaded (/lib/systemd/system/lightdm.service; indirect; vendor pres>
     Active: active (running) since Mon 2022-01-10 13:57:15 JST; 1 years 5 mont>
       Docs: man:lightdm(1)
   Main PID: 1457 (lightdm)
      Tasks: 5 (limit: 4435)
     CGroup: /system.slice/lightdm.service
             ├─1457 /usr/sbin/lightdm
             └─1475 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/ligh>

標準のGDM3ではx11vncが動作しないので、LightDMを導入する必要があるようですが、今回は設定変更の必要なし。

x11vncのインストール

x11vncがインストールされているか確認

$ apt-cache policy x11vnc
x11vnc:
  インストールされているバージョン: (なし)
  候補:               0.9.16-3
  バージョンテーブル:
     0.9.16-3 500
        500 http://ports.ubuntu.com/ubuntu-ports focal/universe arm64 Packages

x11vncのインストール

$ sudo apt install x11vnc

パスワードファイルの作成

$ sudo x11vnc -storepasswd /etc/.vncpasswd
Enter VNC password: 
Verify password:    
Write password to /etc/.vncpasswd?  [y]/n y
Password written to: /etc/.vncpasswd

動作テスト

$ sudo x11vnc -auth guess -display :0 -rfbauth /etc/.vncpasswd -rfbport 5900 -forever -loop -noxdamage -repeat -shared

Windows PCのVNCViewerから接続。画面のコピーが表示されればOK。
Windows側はUltraVNCやVNCViewerなど適当なViewerを使いました。

自動起動の設定

サーバPC(Ubuntu)起動時にsystemdで自動起動するようユニットファイルを作成します。

$ sudo nano /etc/systemd/system/x11vnc.service
[Unit]
Description=x11vnc (Remote access)
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -display :0 -rfbauth /etc/.vncpasswd -rfbport 5900 -forever -loop -noxdamage -repeat -shared
ExecStop=/bin/kill -TERM $MAINPID
ExecReload=/bin/kill -HUP $MAINPID
KillMode=control-group
Restart=on-failure

[Install]
WantedBy=graphical.target

systemdへ登録して起動する。

$ sudo systemctl daemon-reload
$ sudo systemctl enable x11vnc
Created symlink /etc/systemd/system/graphical.target.wants/x11vnc.service → /etc/systemd/system/x11vnc.service.
$ sudo systemctl start x11vnc

物理ディスプレイ無しでのVNC接続

物理ディスプレイに接続しなくても接続できるようにしたいので、ダミーのビデオドライバを設定していきます。

ダミービデオドライバインストール

sudo apt-get install xserver-xorg-video-dummy

設定ファイル

 cvt 1366 768
# 1368x768 59.88 Hz (CVT) hsync: 47.79 kHz; pclk: 85.25 MHz
Modeline "1368x768_60.00"   85.25  1368 1440 1576 1784  768 771 781 798 -hsync +vsync

上記で取得した値を入れ込みつつ新規ファイルを作成。ファイル名の頭の数字は優先度のため同ディレクトリのファイルと被らないように命名します。

$ sudo nano /usr/share/X11/xorg.conf.d/20-dummy.conf
Section "Monitor"
    Identifier "Monitor0"
    HorizSync 5.0-200.0
    VertRefresh 5.0-200.0
    # 1368x768 59.88 Hz (CVT) hsync: 47.79 kHz; pclk: 85.25 MHz
    Modeline "1368x768_60.00"   85.25  1368 1440 1576 1784  768 771 781 798 -hsync +vsync
EndSection

Section "Device"
    Identifier "Monitor0"
    Driver "dummy"
EndSection

Section "Screen"
    DefaultDepth 24
    Identifier "Screen0"
    Device "Card0"
    Monitor "Monitor0"
    SubSection "Display"
    Depth 24
    Modes "1368x768"
    EndSubSection
EndSection

上記設定で物理ディスプレイ無しでVNC接続できるようになりました。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?