22
27

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 5 years have passed since last update.

[メモ] Raspberry Pi : VNCサーバ設定(自動起動)

Last updated at Posted at 2016-06-11

概要

RPi_vncviewer3.png

ためした環境

  • Raspbeey Pi 2 / 3
  • 2016-05-27-raspbian-jessie.img (X使うので、liteじゃないよ)

手順

その1: systemd

  1. いつもの(microSDにimgやいて、sudo apt-get update; sudo apt-get upgrade -y; sudo reboot..)

  2. インストール:
    sudo apt-get install -y tightvncserver

  3. 手動で一回立ち上げて、パスワード設定:
    vncserver :1

  4. systemdのファイル編集:
    sudo vi /etc/systemd/system/vncserver@.service

    /etc/systemd/system/vncserver@.service

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=pi
PAMName=login
PIDFile=/home/pi/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target

5. サービス登録:<br>`sudo systemctl daemon-reload && sudo systemctl enable vncserver@1.service`
6. 再起動:<br>`sudo reboot`
7. `vncviewer.exe`(Windows クライアント)をダウンロードインストール
    - [RealVNC](https://www.realvnc.com/download/viewer/windows/) 名前とEmailの登録が必要
      <br>![RPi_vncviewer.png](https://qiita-image-store.s3.amazonaws.com/0/75594/4f18afcb-e3fb-4ea6-2647-e96eedc5b93c.png)
    - [TigerVNC](https://github.com/TigerVNC/tigervnc/releases) => [Binaries are available from bintray:](https://bintray.com/tigervnc/stable/tigervnc/1.6.0)
      <br>![RPi_vncviewer2.png](https://qiita-image-store.s3.amazonaws.com/0/75594/2819e920-ed1b-b736-647c-20fea3c22139.png)

8. `VNC Server:`へ、"ラズパイのIPアドレス:5901"を入れて `[Connect]`、パスワードいれてログイン
![RPi_vncviewer3.png](https://qiita-image-store.s3.amazonaws.com/0/75594/91414013-8506-f12e-5463-5399a0e4ecf2.png)

9. もうテレビでGUI loginしなくてもいいなら、Textログインでいいよね??
 - `sudo raspi-config` で、`3 Boot Options` > `B1 Console` を選択、再起動。

### その2: `lighdm`
1. いつもの(microSDにimgやいて、`sudo apt-get update; sudo apt-get upgrade -y; sudo reboot`..)
2. インストール: <br>`sudo apt-get install -y tightvncserver`
3. 手動で一回立ち上げて、パスワード設定: <br>`vncserver :1`
<br>やらないと、パスなしになる
4. `lightdm`設定編集:<br>`sudo vi /etc/lightdm/lightdm.conf`

    ```txt:/etc/lightdm/lightdm.conf
...
... 最後方。コメントはずして編集
[VNCServer]
enabled=true
command=Xvnc
port=5900
width=1280
height=800
depth=24
  1. sudo raspi-config3 Boot Options
    • 自動ログイン(デフォルト): B4 Desktop Autologin を選択
    • ログインスクリーン: B3 Desktop を選択

      RPi_vncviewer4.png
    • !!! コンソールを選ぶとlightdmが自動起動しない
  2. sudo reboot
  3. vncviewer.exe(Windows クライアント)をダウンロードインストール、
  4. VNC Server:へ、"ラズパイのIPアドレス:5900"を入れて [Connect]、パスワードいれてログイン

その他

  • 画面のサイズをかえたい

    設定ファイル/etc/systemd/system/vncserver@.serviceの1280x800を変更。サービス再起動。

    sudo systemctl daemon-reload && sudo systemctl restart vncserver@1.service
  • セッションを増やす?

    sudo systemctl enable vncserver@2.service で、IP_address:5902でログインできるが、、設定ファイルがUser=pi...

設定ログ

pi@raspberrypi:~ $ sudo apt-get install -y tightvncserver 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  xfonts-base
Suggested packages:
  tightvnc-java
The following NEW packages will be installed:
  tightvncserver xfonts-base
0 upgraded, 2 newly installed, 0 to remove and 33 not upgraded.
Need to get 6,736 kB of archives.
After this operation, 9,895 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main tightvncserver armhf 1.3.9-6.5 [555 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main xfonts-base all 1:1.0.3 [6,181 kB]
Fetched 6,736 kB in 3s (2,013 kB/s)      
Selecting previously unselected package tightvncserver.
(Reading database ... 118080 files and directories currently installed.)
Preparing to unpack .../tightvncserver_1.3.9-6.5_armhf.deb ...
Unpacking tightvncserver (1.3.9-6.5) ...
Selecting previously unselected package xfonts-base.
Preparing to unpack .../xfonts-base_1%3a1.0.3_all.deb ...
Unpacking xfonts-base (1:1.0.3) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for fontconfig (2.11.0-6.3) ...
Setting up tightvncserver (1.3.9-6.5) ...
update-alternatives: using /usr/bin/tightvncserver to provide /usr/bin/vncserver (vncserver) in auto mode
update-alternatives: using /usr/bin/Xtightvnc to provide /usr/bin/Xvnc (Xvnc) in auto mode
update-alternatives: using /usr/bin/tightvncpasswd to provide /usr/bin/vncpasswd (vncpasswd) in auto mode
Setting up xfonts-base (1:1.0.3) ...
pi@raspberrypi:~ $ vncserver :1 

You will require a password to access your desktops.

Password: 
Verify:   
Would you like to enter a view-only password (y/n)? n

New 'X' desktop is raspberrypi:1

Creating default startup script /home/pi/.vnc/xstartup
Starting applications specified in /home/pi/.vnc/xstartup
Log file is /home/pi/.vnc/raspberrypi:1.log

pi@raspberrypi:~ $ sudo vi /etc/systemd/system/vncserver@.service
pi@raspberrypi:~ $ sudo systemctl daemon-reload && sudo systemctl enable vncserver@1.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vncserver@1.service to /etc/systemd/system/vncserver@.service.
pi@raspberrypi:~ $ sudo reboot

22
27
2

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
22
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?