LoginSignup
0
0

More than 3 years have passed since last update.

ラズパイ3 導入メモ1

Last updated at Posted at 2019-04-24

概要

Windows7 のサポート寿命が近いので Ubuntu に乗り換えた。
ついでに Raspberry Pi 3 B+ を購入した。
だが、キーボード・マウス・ディスプレイを用意したくはない。
Ubuntu を入れたノートPC から SSH にて操作することにしよう。
とりあえず Wifi ではなく有線LAN にて。

後々 Elixir 突っ込んで遊びたい。

環境

  • Ubuntu 18.04
  • Raspbian Stretch Lite April 2019

OS

GUI は必要ないので Raspbian Stretch Lite を使う。

ダウンロード

公式サイトより Raspbian Stretch Lite をダウンロードする。

Download Raspbian for Raspberry Pi

イメージの書き込み

GParted を使って SDカード(32GB)の内容を削除した。
下記コマンドラインにて書き込み。数分待つ。

Ubuntu
$ zcat 2019-04-08-raspbian-stretch-lite.zip |
> sudo dd status=progress bs=32M of=/dev/sdb

1794834432 bytes (1.8 GB, 1.7 GiB) copied, 105 s, 17.1 MB/s
0+43780 レコード入力
0+43780 レコード出力
1803550720 bytes (1.8 GB, 1.7 GiB) copied, 266.54 s, 6.8 MB/s

Pi-GParted_00.png

一度 SDカードを抜いて自動マウントさせた。

SSH の有効化

マウントされた boot rootfs が Raspbian のパーティション。
SSH を有効化するには、
boot 直下に ssh という名の空ファイルを置いておくらしい。

Ubuntu
$ cd /media/UserName
$ ll
合計 15
drwxr-x---+  4 root      root      4096  4月 19 01:08 ./
drwxr-xr-x   3 root      root      4096  3月 15 01:18 ../
drwxr-xr-x   3 UserName  UserName  2560  1月  1  1970 boot/
drwxr-xr-x  21 root      root      4096  4月  8 18:46 rootfs/

$ touch boot/ssh

IPアドレスの固定化

ここで SDカードをラズパイに差し込めば SSH で接続できるが、
IPアドレスを固定しておいた方が楽だ。

Ubuntu
$ cd /media/UserName/rootfs
$ sudo nano etc/dhcpcd.conf

なんか色々書いてあるが、最終行に下記を追加した。

dhcpcd.conf
# 最終行に追加
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

SSH

ログイン

  • ID: pi
  • PW: raspberry
Ubuntu
$ ssh pi@192.168.1.100
The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established.
ECDSA key fingerprint is SHA256:********.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.100' (ECDSA) to the list of known hosts.

よく知らない奴に繋がろうとしてるけどいい? yes

Ubuntu=>ラズパイ
pi@192.168.1.100's password: 
Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.


Wi-Fi is disabled because the country is not set.
Use raspi-config to set the country before use.

ログイン成功。
Debian GNU/Linux はフリーだぜって書いてある。

SSH は有効化されているけど、
ユーザー pi とデフォのパスワードのままは危険だよと言っている。

また、あんたの国の設定を知らないから Wifi は使えないよ。
raspi-config でよろしく、らしい。

WARNING

Raspbian の設定が変更されると、
クライアント側に保存された情報(フィンガープリント)と食い違うことがある。

Ubuntu
$ ssh pi@192.168.1.100

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:********.
Please contact your system administrator.
Add correct host key in /home/UserName/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/UserName/.ssh/known_hosts:3
  remove with:
  ssh-keygen -f "/home/UserName/.ssh/known_hosts" -R "192.168.1.100"
ECDSA host key for 192.168.1.100 has changed and you have requested strict checking.
Host key verification failed.

$ ssh-keygen -f "/home/UserName/.ssh/known_hosts" -R "192.168.1.100"
# Host 192.168.1.100 found: line 3
/home/UserName/.ssh/known_hosts updated.
Original contents retained as /home/UserName/.ssh/known_hosts.old

説明にある通り ssh-keygen でとりあえず対処できた。

初期設定

raspi-config

ラズパイ
$ sudo raspi-config

raspi-config.png

Change User Password

raspberry から変更しておこう。

Network Options

Hostname

ホスト名は、アルファベット(大小区別無)・数字・ハイフンだけだと注意書きが出る。

Localisation Options

Change Locale

初めから en_GB.UTF-8 UTF-8 にはチェック済み。
加えて ja_JP.EUC-JP EUC-JP ja_JP.UTF-8 UTF-8 にチェックを入れた。
ちなみにチェックはスペースキーですよ。

<Ok> で画面が遷移すると
「デフォはどれ?」と聞かれるので ja_JP.UTF-8 UTF-8 を選んだ。

Change Timezone

Asia/Tokyo

Change Keyboard Layout

自動的に設定された?はてさて。

Advanced Options

Expand Filesystem

SDカードの容量目一杯使ってよ、ということらしい。

Pi-GParted_01.png

うむ。

Update

raspi-config 自体の更新。

安定版での更新

ラズパイ
$ sudo apt update
$ sudo apt upgrade
$ sudo apt dist-upgrade

最新版への更新

通常は必要ない。

ラズパイ
$ sudo apt install rpi-update
$ sudo rpi-update

再起動・反映

ラズパイ=>Ubuntu=>ラズパイ
$ sudo reboot
...
$ ssh pi@xxx.local
pi@xxx.local's password:

シャットダウン

ラズパイ
$ sudo shutdown -h now

OS は落ちるが、電源は切れないよ。コード引っこ抜け。

ラズパイ3 導入メモ2 につづく。

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