LoginSignup
25
34

More than 5 years have passed since last update.

Raspberry Piの初期設定

Posted at

はじめに

Raspberry Piの初期設定で特によくおこなうものをメモする。なお、OSはRaspbian Stretch Liteを、バージョンは現時点で最新のものを使用する:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.4 (stretch)
Release:    9.4
Codename:   stretch
$ uname -a
Linux raspberrypi 4.14.68-v7+ #1140 SMP Wed Sep 5 17:17:58 BST 2018 armv7l GNU/Linux

パッケージリストとパッケージの更新

$ sudo apt-get update
$ sudo apt-get upgrade

OSの更新

$ sudo apt-get dist-upgrade

ファームウェアの更新

$ sudo apt-get install rpi-update
$ sudo rpi-update
$ sudo reboot

raspi-configの更新

$ sudo raspi-config

"8 Update" を選択する。

パスワードの更新

$ sudo raspi-config

"1 Change User Password" からおこなう。

ファイアウォールの設定

$ sudo apt-get install ufw  # ufwのインストール
$ sudo ufw allow 22  # ポートの開放
$ sudo ufw default deny  # 許可されたポート以外を閉じる
$ sudo ufw enable  # ufwの有効化
$ sudo ufw status  # ファイアウォールの設定を確認
Status: active

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere
22 (v6)                    ALLOW       Anywhere (v6)

sshの設定

$ sudo raspi-config

"5 Interfacing Options" -> "P2 SSH" -> "Would you like the SSH server to be enabled?" -> "Yes" によりsshが有効化される。

sshの設定ファイルは/etc/ssh/sshd_configにある。

Port 22  # ポートの設定
PermitRootLogin no  # rootログインの禁止
PasswordAuthentication no  # パスワード認証の禁止

などを適宜設定する。

ロケールの変更

$ sudo raspi-config

"4 Localisation Options" -> "I1 Change Locale" からおこなう。

タイムゾーンの変更

$ sudo raspi-config

"4 Localisation Options" -> "I2 Change Timezone" からおこなう。

ファイルシステムの拡張

$ sudo raspi-config

"7 Advanced Options" -> "A1 Expand Filesystem" からおこなう。

IPアドレスの固定

$ ifconfig  # 現在のIPアドレスを確認する
$ sudo vim /etc/dhcpcd.conf  # 上で確認したIPアドレスに固定する
$ tail -n 4 /etc/dhcpcd.conf  # たとえば、下の4行のように末尾に記入する
interface eth0
static ip_address=192.168.1.19/24  固定したいIPアドレス
static routers=192.168.1.1  # デフォルトゲートウェイ
static domain_name_servers=192.168.1.1  # DNSサーバ
25
34
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
25
34