SDカードを準備する
Raspbianをダウンロードする
Download Raspbian for Raspberry PiからRaspbianをダウンロードする。少し時間がかかります。
SDカードにRaspbienのディスクイメージを書き込む
Macの場合
「RPi-sd card builder v1.2」をダウンロードしてインストールする。
「RPi-sd card builder v1.2」を起動し、SD card setup – Raspberry Pi – Macにある手順通りに進めるとRaspbianの入ったSDカードが作成される。
Windowsの場合
「Win32DiskImager」をダウンロードしてインストールする。
「Win32DiskImager」を起動し、ダウンロードしたディスクイメージを選択してDviceでSDカードを選択、「Write」をクリックするとRaspbianの入ったSDカードが作成される。
RaspberryPiを起動して接続する
RaspberryPiを起動する
作成したSDカードをRaspberryPiに挿し、LANケーブル、ディスプレイケーブル(HDMI)、USBキーボードを挿してから電源を挿す。RaspberryPiには電源スイッチが無いため、延長タップなどのスイッチを利用して電源のON-OFFを行うといい。
RaspberryPiに接続する
電源を入れると初期設定画面が現れる。これは後でも設定できるので、とりあえず今はexpand_rootfsと、もし、sshがdisableになっていればenableにする。
以下の作業はLAN内の他のPCからSSHでログインして行うことができるので、ディスプレイやキーボードは取り外してよい
ログイン
初期設定では、ID:「pi」、パスワード:「raspberry」でログインできるので、ログインする。
$ ssh pi@raspberrypi.local
pi@raspberrypi.local's password:
固定IPを割り当てる
IPアドレスの割り当ては、DHCPサーバに任せて、DHCPサーバ側で、固定IPを割り当てるようにする。
先にルータの設定画面で、RaspberryPiのMACアドレスに固定IPを割り当てるように設定しておくこと。
設定の仕方はルータによって異なるが、「Aterm WR9500N」では、詳細設定>DHCP固定割当設定で割り当てられる(他のルータでもだいたい同じ)
MACアドレスはifconfig
で調べられる。
ルータの設定が終了したら、RaspberryPi側の設定をする。
$ sudo vi /etc/network/interfaces
...略...
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp ←ここがdhcpになっているか確認
...略...
$sudo /etc/init.d/networking restart
セキュリティに関する設定をする
ユーザの権限などを変える
rootパスワードを設定し、suでrootになる。
pi@raspberrypi ~ $ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
pi@raspberrypi ~ $ su
Password:
root@raspberrypi:/home/pi#
新しいユーザを追加し、sudoerに登録する。ユーザ「pi」はsudoerから外す。
root@raspberrypi:/home/pi# adduser hoge
Adding user `hoge' ...
Adding new group `hoge' (1002) ...
Adding new user `hoge' (1001) with group `hoge' ...
Creating home directory `/home/hoge' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for hoge
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
root@raspberrypi:/home/pi# visudo
...略...
#includedir /etc/sudoers.d
#pi ALL=(ALL) NOPASSWD: ALL
hoge ALL=(ALL) NOPASSWD: ALL
suを実行できるユーザをsudoグループに制限する。
「pi」をsudoグループから外し、新しく作ったユーザをsudoグループに入れる。
# vi /etc/pam.d/su
# (Replaces the `SU_WHEEL_ONLY' option from login.defs)
# auth required pam_wheel.so
auth required pam_wheel.so group=sudo
# vi /etc/group
...略...
sudo:x:27:hoge ←piを消去して新しく作ったユーザを追記
...略...
sshを公開鍵認証方式に変える
公開鍵を登録する準備をする
hoge@raspberrypi ~ $ cd
$ mkdir .ssh
$ chmod 700 .ssh
$ vi .ssh/authorized_keys
(ここにログイン元の「id_rsa.pub」をコピーする。公開鍵がなければ作る)
「root」ログインの禁止とパスワードログインの禁止
この作業を行うと、パスワードログインができなくなり、公開鍵認証でうまくログインできなかった場合にハマるので、一度公開鍵認証でのログインテストをしたほうがいいかも・・・というか私は思いっきりハマりました
# vi /etc/ssh/sshd_config
...略...
# Authentication:
LoginGraceTime 120
#PermitRootLogin yes
PermitRootLogin no
StrictModes yes
...略...
# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes
PasswordAuthentication no
...略...
SSHサーバの再起動
# service ssh restart
ログインできれば成功
$ ssh hoge@raspberrypi.local
Identity added: /Users/fuga/.ssh/id_rsa (/Users/fuga/.ssh/id_rsa)
Linux raspberrypi 3.18.11+ #781 PREEMPT Tue Apr 21 18:02:18 BST 2015 armv6l
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.
Last login: Mon Aug 24 11:56:37 2015 from piyopiyo.local
hoge@raspberrypi ~ $
ファイアウォールのインストールと設定
ここでは設定が簡単な「ufw」を使うことにする。
$ sudo apt-get install ufw
有効にする前にSSHを許可しておかないとSSHが切れるので注意
$ sudo ufw allow ssh
Rules updated
$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
次はScanSnapを繋いでみるよ
RaspberryPiで遊んでみたーその2 ScanSnap S1500 をRaspberryPiに繋いでスキャンしたものをDropboxにアップロードする