公式ドキュメント
環境
- Raspbian(version 4.19)
Docker Install
こちらのコマンドを入力すると終わりです.curl -sSL https://get.docker.com | sh
お疲れさまです.私がしたRaspberryPiの設定は, 「RaspberryPiの設定 まとめリスト」にまとめてあります.
sshしていることを前提にします.
aptのアップデートをします. ちまたではapt-getが多いですが, apt-getの上位互換がaptなので, aptを使うほうがよろしいらしい.
ソースはこちら「Is ‘apt-get’ deprecated? [duplicate]」
まぁ, aptもapt-getもパッケージツールなので, 必要なものがaptに無ければapt-getを使うというぐらいで良いのかも.
ではssh先でaptのアップデート.
$ sudo apt update
$ sudo apt upgrade
aptのみで良いですが, apt-getもやりたい方はこちららしいです.
$ sudo apt-get update
$ sudo apt-get upgrade
$ apt-get dist-upgrade
ssh先で次のコマンドを打ちます.
$ sudo rpi-update
その後, 再起動すれば終わりです.
$ sudo reboot
いちいち手動でアップデートをするのもめんどくさく, 忘れることも多いと思うので自動アップデートも設定します. 次のコマンドを打ちましょう.
$ # 設定ファイルの作成, aptの自動アップデート設定
$ sudo sh -c 'echo "59 23 * * * /usr/bin/apt update ; /usr/bin/apt -y upgrade ; /usr/bin/apt -y autoremove ; /usr/bin/apt clean" > /root/crontab_root_file'
$ # ファームウェアのアップデート自動化
$ sudo sh -c 'echo "59 23 * * * /usr/bin/rpi-update" >> /root/crontab_root_file'
$ # 自動アップデートの登録
$ sudo crontab -u root /root/crontab_root_file
ちょっとややこしいと思いますが, コマンドを追加している部分は
「echo “59 23 * * * /usr/bin/apt update ; /usr/bin/apt -y upgrade ; /usr/bin/apt -y autoremove ; /usr/bin/apt clean”」
などです.
数字の部分「59 23 * * *」は順に「分 時 日 月 曜日」となります.
毎日23時59分に
「apt update ; apt -y upgrade ; apt -y autoremove ; apt autoclean"」
というコマンドを実行します. 自動アップデートや, アップデートした後に不要なものの削除などの設定です. ファームウェアのアップデートも同じです.
実際に登録されたかは, 次のコマンドを打てば良いです.
$ # 登録されたリストを表示
$ sudo crontab -u root -l
59 23 * * * /usr/bin/apt update ; /usr/bin/apt -y upgrade ; /usr/bin/apt -y autoremove ; /usr/bin/apt clean
59 23 * * * /usr/bin/rpi-update
「/usr/bin/apt update ; /usr/bin/apt -y upgrade ; /usr/bin/apt -y autoremove ; /usr/bin/apt clean」などが登録されているのがわかります.
ワンライナーみたいにするなら,
$ (sudo crontab -u root -l ; echo "59 23 * * * /usr/bin/apt update ; /usr/bin/apt -y upgrade ; /usr/bin/apt -y autoremove ; /usr/bin/apt clean" | sort | uniq) | sudo crontab -u root -
$ (sudo crontab -u root -l ; echo "59 23 * * * /usr/bin/rpi-update" | sort | uniq) | sudo crontab -u root -
こんな感じ.
こういうアップデートは再起動しないと設定が反映されない場合もあるので, 時々再起動しなければいけない場合があります.
自分はそれがめんどくさいので, 定期的に再起動してくれるようにこれも設定しました.
$ # 設定ファイルに追記
$ sudo sh -c 'echo "0 4 * * 1 /sbin/reboot" >> /root/crontab_root_file'
$ # 自動アップデートの登録
$ sudo crontab -u root /root/crontab_root_file
これは任意でやって下さい.
私がしたRaspberryPiの設定は, 「RaspberryPiの設定 まとめリスト」にまとめてあります.
IPアドレスとはパソコンの住所のことです. 残念ながらパソコンさんはDHCPという仕組みがあり, 繋がるたびに住所が変わるため, IPアドレスは固定ではありません. ホテルに泊まるような感じですかね. 一度ホテルをチェックアウトしてもう一度泊まると, 部屋が変わってしまう感じです.
だから, 「お前の住所は絶対ここだからな」って決めるのがIPアドレスの固定です. 住所を決めることで, 遠隔操作をする時は「こっちに行けばいんだね」というのがわかります.
…うまく説明できてない感があるので, ここの解説サイトを見て下されば概念がわかると思います.「IPアドレス」
ちなみに, IPアドレスという数字で管理しているものを, 人間がわかるように文字にしたものがhostnameです.
「IPアドレスを固定する」を参考にして, inet, netmask, ゲートウェイ(Gateway)を調べます.
$ # wlan0がwifiのこと. inetとnetmaskが分かる.
$ ifconfig
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.90 netmask 255.255.255.0 broadcast 192.168.0.255
~~省略~~
$ # ゲートウェイを調べる.
$ route
カーネルIP経路テーブル
受信先サイト ゲートウェイ ネットマスク フラグ Metric Ref 使用数 インタフェース
default 192.168.0.1 0.0.0.0 UG 303 0 0 wlan0
~~ 省略 ~~
上の結果から,
ということがわかりました.
netmaskの255.255.255.0の4番目の数字が0なのは, inetの192.168.0.90の4番目の数字「90」は「2~254」までで好きにしていいよ―ってことです.
次のコマンドを打ちます.
「static ip_address=192.168.0.90」の「90」は, 「2~254」の間の好きな数字にして下さい. あとはinetの4番目の数字を1にして下さい.
echo "
interface wlan0
static ip_address=192.168.0.90
static routers=192.168.0.1
static domain_name_servers=192.168.0.1" >> /etc/dhcpcd.conf
その後再起動します. 間違っていないところがないかしっかり確認して下さい.
$ sudo reboot
30秒ぐらい待って, sshしてみます.
「ssh ユーザー名@固定IPアドレス」でコマンドを打ってみましょう. これででき…ないw
$ ssh hoge@192.168.0.90
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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:2V2gPFgBzJKoVhE09mEer3kvIO1OenyfvGwppkNhwDs.
Please contact your system administrator.
Add correct host key in /Users/${USER}/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/${USER}/.ssh/known_hosts:23
ECDSA host key for 192.168.0.90 has changed and you have requested strict checking.
Host key verification failed.
なんか「接続先のパソコン, 前のと似ているけど何かが変わったパソコンだから危ないよ!」って言っています. どうせOSのアップデートかIPの固定のどちらかで変わったので, 古い情報の入ったファイルを捨てます.
$ rm ~/.ssh/known_hosts
これでもう一度sshすると…
$ ssh hoge@192.168.0.90
The authenticity of host '192.168.0.90 (192.168.0.90)' can't be established.
ECDSA key fingerprint is SHA256:2V2gPFgBzJKoVhE09mEer3kvIO1OenyfvGwppkNhwDs.
Are you sure you want to continue connecting (yes/no)? yes # yesと入力
Warning: Permanently added '192.168.0.90' (ECDSA) to the list of known hosts.
Linux raspberrypi 4.14.42-v7+ #1114 SMP Mon May 21 16:39:21 BST 2018 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.
Last login: Thu May 24 19:49:27 2018 from xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
hoge@raspberrypi:~ $
これでできた!
これでもできなかった場合は, hostnameは変わっていないので, hostnameでsshして何が間違っているか調べましょう. もう一度上の手順を繰り返してみたり, 他のサイトを参考にするのもあり.
$ ssh hoge@raspberrypi.local
~~原因を調べる~~
hostnameは「raspberrypi.local」です. 次のコマンドを打ちましょう.
今回は, 例としてhostnameを「hogepi.local」にしたいと思います.
$ ssh hoge@raspberrypi.local
$ # hogepi.localに変更
$ sudo raspi-config nonint do_hostname hogepi.local
[sudo] password for hoge: #hogeのパスワードを打つ
$ sudo reboot
30秒ぐらい待って, sshしてみましょう.
$ ssh hoge@hogepi.local
hoge@hogepi:~ $
これで「hoge@」以降の表示が変わったことがわかると思います. 以上でhostnameの変更は終了です.
私がしたRaspberryPiの設定は, 「RaspberryPiの設定 まとめリスト」にまとめてあります.
まず, ユーザーの変更をしなければいけません.
sshを導入したと思いますが, 遠隔操作ができるというメリットは, 他の人もアクセスできる可能性があるというデメリットを生みます.
実際, 「Raspbian install on Raspberry Pi 3」では, 私の手順をなぞればsshができましたよね. 他の人が同じ場所で真似をすれば, 同じことができるということです.
ということで, ユーザー名とパスワードを変更するのはセキュリティ的に大切です. やりましょう.
手順としては,
という感じです.
ちなみに, ユーザーtempを使うのはユーザーpiが使われている場合, 名前の変更ができないからです.
pi@raspberrypi:~ $ sudo usermod -l hoge pi
usermod: user pi is currently used by process 551
piの中で作業しているので, piを使っていると見なされています.
次のコマンドを打ちましょう. $から後ろがコマンドです.
$ # ユーザーpiにsshする.
$ ssh pi@raspberrypi.local
Linux raspberrypi 4.14.42-v7+ #1114 SMP Mon May 21 16:39:21 BST 2018 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.
Last login: Sun May 27 14:53:10 2018 from xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
$ # tempユーザーの作成
$ sudo useradd -M temp
$ # sudoをtempユーザーでも使えるようにする.
$ sudo gpasswd -a temp sudo
Adding user temp to group sudo
$ # tempユーザーのパスワードを設定
$ sudo passwd temp
Changing the password for group temp
New Password:
Re-enter new password:
$ # logoutする.
$ exit
logout
Connection to raspberrypi.local closed.
ユーザー名は適当で良いです. 今回はtempというユーザー名にしています. tempという名前は, すぐ削除する一時的なものにつける事が多い, 慣習的な名前です.
「New Password:」は適当なパスワードを設定して下さい. どうせすぐ削除するので.
先程と同様の手順で, ユーザーtempにsshします. その後,
piの名前を変更します. 好きな名前に変更して良いですが, 今回は例としてhogeというユーザー名にします.
次のコマンドを打ちましょう.
$ # ユーザーtempにsshする.
$ ssh temp@raspberrypi.local
temp@raspberrypi.local's password: # 1で設定したtempのパスワードを入れる
Linux raspberrypi 4.14.42-v7+ #1114 SMP Mon May 21 16:39:21 BST 2018 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.
Last login: Sun May 27 15:24:36 2018 from xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
Could not chdir to home directory /home/temp: No such file or directory
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.
$ # エラーが出ないように, 一応piのprocessをkillする.
$ sudo pkill -u pi
[sudo] password for temp: # 1で設定したtempのパスワードを入れる
$ # 好きなユーザー名に変更. 今回はhoge.
sudo usermod -l hoge -d /home/hoge -m pi
$ # groupを変更する.
$ sudo groupmod -n hoge pi
$ exit
Connection to raspberrypi.local closed.
確認のため, hogeにsshします.
$ ssh hoge@raspberrypi.local
Linux raspberrypi 4.14.42-v7+ #1114 SMP Mon May 21 16:39:21 BST 2018 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.
Last login: Sun May 27 14:57:06 2018 from xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
hoge@raspberrypi:~ $
sshでき, 「hoge@raspberrypi:~ $ 」になっていると思います. これで, ユーザー名の変更は終わりです.
ユーザーtempを削除します. パスワードを聞かれますが, 「raspberry」にして下さい.
$ ssh hoge@raspberrypi.local
Linux raspberrypi 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 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.
Last login: Wed May 23 12:25:05 2018 from xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
$ # ユーザーtempを削除. passwordは「raspberry」にする.
$ sudo userdel temp
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for hoge: # raspberryと入力
hoge@raspberrypi:~ $
これでtempが削除されました.
ワンライナーみたいな感じで, 新しいユーザーを作らなくてもユーザーが変更できるコマンドを作りました. 上の1~3までこれでできます. sudo suができなければダメですが…
$ ssh pi@raspberrypi.local
$ sudo su ; exit
$ /bin/bash -c 'NEWNAME=hoge; OLDNAME=pi; nohup sleep 3; pkill -u ${OLDNAME}; usermod -l ${NEWNAME} -d /home/${NEWNAME} -m ${OLDNAME}; groupmod -n ${NEWNAME} ${OLDNAME} &' & exit
NEWNAME=新しい名前, OLDNAME=古い名前を入れれば, すぐに変更できると思います.
でも複雑さが増してしまったので, 上の手順を素直にやったほうが良いかと.
変更したユーザーのパスワードを変えていきます.
「[sudo] password for hoge:」のパスワードは「raspberry」にして下さい.
その後, 新しいパスワードを打っていきます.
$ ssh hoge@raspberrypi.local
Linux raspberrypi 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 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.
Last login: Wed May 23 13:24:35 2018 from xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
$ # hogeのパスワードを変更
hoge@raspberrypi:~ $ sudo passwd hoge
[sudo] password for hoge: # raspberryと入力
Enter new UNIX password: # 新しいパスワードを入力
Retype new UNIX password: # もう一度新しいパスワードを入力
passwd: password updated successfully
hoge@raspberrypi:~ $
これで, パスワードの変更は終了です.
以上で, ユーザー名, パスワードの変更は終了になります.
最後に, あまり詳しく説明しません(他の方が色々説明なさってます)が, piの残り物を消します.
ssh先で次のコマンドを打ちます.
$ sudo rm /etc/sudoers.d/010_pi-nopasswd
これでpiユーザーの残骸もなくなりました.
これで終了です. 滅多なことがない限り復元しないほうが良いですが, 復元したい場合は以下のコマンドを打って下さい.
sudo sh -c 'echo "pi ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/010_pi-nopasswd'
ちょっとめんどくさいですが, やっていたほうが良い設定です. 是非とも頑張って設定してみて下さい.
私がしたRaspberryPiの設定は, 「RaspberryPiの設定 まとめリスト」にまとめてあります.
今回の設定のメリット
今回の設定のデメリット
時間と場所の設定を行います.
デフォルトが何かはわかりませんが, 日本と違うので.
sshしていることを前提にします.
ssh先で次のコマンドを打ちます.
$ # timezoneを日本(Japan)に設定
$ sudo raspi-config nonint do_change_timezone Japan
[sudo] password for hoge:
Current default time zone: 'Asia/Tokyo'
Local time is now: Thu May 24 00:24:35 JST 2018.
Universal Time is now: Wed May 23 15:24:35 UTC 2018.
これで終了です. なお, 次のコマンドを打つことで, どの国を選べるかわかるそうです.
$ ls /usr/share/zoneinfo/
Africa Chile Factory Iceland localtime Portugal Turkey
America CST6CDT GB Indian MET posix UCT
Antarctica Cuba GB-Eire Iran Mexico posixrules Universal
Arctic EET GMT iso3166.tab MST PRC US
Asia Egypt GMT0 Israel MST7MDT PST8PDT UTC
Atlantic Eire GMT-0 Jamaica Navajo right WET
Australia EST GMT+0 Japan NZ ROC W-SU
Brazil EST5EDT Greenwich Kwajalein NZ-CHAT ROK zone1970.tab
Canada Etc Hongkong leap-seconds.list Pacific Singapore zone.tab
CET Europe HST Libya Poland SystemV Zulu
localeとは文字コードのことです. 文字コードとは, コンピューターさんが文字画像をちゃんと表示できるように対応付けするものです.
デフォルトの文字コードでは日本語は対応されていないので, 対応できるようにしましょう.
$ sudo raspi-config nonint do_change_locale ja_JP.UTF-8
$ sudo locale-gen
これでたぶん出来てる…と思ったのですが, 文字のフォントがそもそも用意されていないので, フォントを用意します.
$ sudo apt install -y jfbterm
これで日本語化は終了です.
何故この設定をやるのかはいまいちわかっていないが…別に簡単なので.
$ sudo raspi-config nonint do_wifi_country JP
[sudo] password for hoge:
OK
終わり.
RaspberryPiにssh以外でキーボードを使う際には必要です. US(アメリカ用)のキーボードになっているので, 日本のキーボードとは違います. なので, 例えば「;」を打ったら「:」が打たれたりします. ほかにも配置が違うので, 変えておきましょう.
次のコマンドを打てば終わりです.
$ sudo raspi-config nonint do_configure_keyboard jp
これで, 「;」を打ったのに「:」が入力されるとかはなくなります.
色々設定していたRasberry Pi3のシステムがぶっ壊れたので, OSの再インストールをする羽目に…
どうせなら最初からSDカード使ってインストールするまでを備考録として残していきます.
OSのダウンロードからSSH設定まで書きます.
ちなみに, ちまたにたくさん備考録が転がっているので, 自分にあったものを選んで下さい. これ大事.
さらにちなみに, 公式のドキュメントは「Raspberry Pi Software Guide」です.
絶対必要なもの
あったら良いもの
今回は, SSH設定をOSインストール前にするので, キーボードとかマウスとかは準備しません. もちろん, あった方が良いではありますが…保険になるし.
文字だけの画面(ターミナル)が怖くない方はできます.
CUI(Command User Interface)は, Terminalというアプリ使いますって話.
OSのダウンロードを行います.
「Raspbian 公式 ダウンロードページ」からRaspbianのダウンロードが行なえます.
下に行くほどぞろぞろありますが, 基本は, ページの上の方にある, NOOBSかRASPBIANのどちらかを選びます.
どちらも機能的に変わりはないのですが, 今回はRASPBIANを使います. (ggったらNOOBSのやり方は「Raspberry PiのOSをインストールしてみた(NOOBS篇)」にあります.)
出典: Raspbian 公式 ダウンロードページ
次に, 「RASPBIAN STRETCH WITH DESKTOP」か「RASPBIAN STRETCH LITE」か選べます. 「RASPBIAN STRETCH LITE」はアプリが色々入っていないので, 今回は「RASPBIAN STRETCH WITH DESKTOP」を選びます.
「RASPBIAN STRETCH WITH DESKTOP」の横の「Download ZIP」を選んで下さい. (というかTorrentあったのかよ懐いな)
出典: Raspbian 公式 Raspbian ダウンロードページ
1.7Gあるので少し時間がかかります.
お茶でもして待ちま…この空き時間にSDカードの初期化をしましょう.
次に, SDカードの初期化をやります.
SDカードを挿して, Terminalを開きましょう. TerminalはFinderを開いて,
アプリケーション(Application) -> ユーティリティ -> ターミナル.app(terminal.app)
をダブルクリックすれば開けます.
アプリの画面が出ればOKです.
次のようにコマンドを打ちます. $の後ろがコマンドです. 下からコピペする時は, $のところの後ろをコピペして下さい.

$ diskutil list
/dev/disk0 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *251.0 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 250.1 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *31.0 GB disk1
1: EFI EFI 209.7 MB disk1s1
2: Microsoft Basic Data RASBIAN 30.8 GB disk1s2
$ # 今回は/dev/disk1のSizeが32GBなので, これじゃろと当たりをつけてやる. ちなみにこれ失敗したらひどいことになる場合もあるので慎重に.
$ diskutil unMountDisk /dev/disk1
Unmount of all volumes on disk1 was successful
$ # RASBIANのところは任意の「英大文字」にして下さい. 英小文字はダメです.
$ diskutil eraseDisk FAT32 RASBIAN /dev/disk1
Started erase on disk1
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Formatting disk1s2 as MS-DOS (FAT32) with name RASBIAN
512 bytes per physical sector
/dev/rdisk1s2: 60194048 sectors in 1881064 FAT32 clusters (16384 bytes/cluster)
bps=512 spc=32 res=32 nft=2 mid=0xf8 spt=32 hds=255 hid=411648 drv=0x80 bsec=60223488 bspf=14696 rdcl=2 infs=1 bkbs=6
Mounting disk
Finished erase on disk1
怖い方はGUIを使っても良いかと.
やり方は「Mac で「SD カード」をフォーマット(初期化)する方法」の「SDカードを初期化する.」の章に書いてあります.
これでSDカードの初期化は終わりです.
自分はここで苦戦しました. 2
SDカードを初期化している間に, ダウンロードが済んだと思います. ...済んだよね?
「XXXX-YY-DD-raspbian-stretch.zip」
みたいなのがダウンロードされたと思うので, それを解凍します.

解凍したら, またTerminalでコマンドを打っていきます.
$ diskutil list
/dev/disk0 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *251.0 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 250.1 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *31.0 GB disk1
1: EFI EFI 209.7 MB disk1s1
2: Microsoft Basic Data RASBIAN 30.8 GB disk1s2
$ # 念のため, もう一度diskutil listで調べてから, /dev/diskを指定する.
$ diskutil unMountDisk /dev/disk1
$ # 「if=」まで書いたら, finderからドラッグ・アンド・ドロップしてくる.
$ # もちろん, パスについて知っているならパスを書く.
$ sudo dd bs=1m of=/dev/disk1 if=<imgのpath>
Password:
~~~しばらく待つ~~~
4724+0 records in
4724+0 records out
4953473024 bytes transferred in 2701.965241 secs (1833285 bytes/sec)
Passwordは, パソコンのパスワードを入れます. 見た目は何も変わらないが, ちゃんと入力されているので, パスワードを入力したらEnterを押して下さい.
Passwordがしっかり入力されると, しばらく止まっているように見えますが, SDカードに書き込んでいます. なのでSDカードに何もしない, ターミナルはそのままでゆっくり待ちましょう.
~ transferred ~とか出てきたら終了です.
Finderのデバイス欄にbootというのができていると思います.
これでimgができました.
SSHとは, アバウトに言うとパソコンを遠隔操作できるようなものです.
SSHの準備をする方法は簡単で, このできたbootの中に「ssh」という何も書いていないファイルを追加するだけです.
実際にTerminalで次のコマンドを打てば終わりです.
$ touch /Volumes/boot/ssh
sshで遠隔操作すると言っても, パソコンがどうにかしてRaspberry Piに「インターネット的に」接続していなきゃダメです. なので
のいずれかの方法を取る必要があります.
今回は3の「Raspberry Piとルーターを無線LAN(Wifi)で繋いで, PCからルーター経由でアクセスする.」をやります.
ルーターにパスワードがある場合を想定しています. パスワードがある場合, Wifiに繋ぐ時にパスワードを要求されるはずです. 無い場合は, 「Wifiの準備.」をスキップして構いません.
また, WifiはRaspberry Pi3 Model Bの場合, 5GHz帯域では認識しないので注意して下さい.3
次のようなものを先程のbootの中に作ります.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP
network={
ssid=<SSID>
psk=<Password>
key_mgmt=WPA-PSK
}
6行目の<SSID>にはwifiのネットワーク名(SSID)を, 7行目の<Password>は, Wifiにつなげる時に打つパスワードを入れて下さい.
ネットワーク名は上のWifiのマークで調べられます.
例えば, SSIDがhogeで, Passwordがhugaなら,
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP
network={
ssid="hoge"
psk="fuga"
key_mgmt=WPA-PSK
}
になります.
後はこれを, 次のコマンドを使ってファイルを作るだけです.
$ echo 'ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP
network={
ssid="hoge"
psk="fuga"
key_mgmt=WPA-PSK
}' > /Volumes/boot/wpa_supplicant.conf
もしどこか間違えても, 修正してもう一度コマンドを打てば良いです.
ファイルが次のように作成されているのを確認して下さい.
これで, Raspbianをインストールする準備は整いました.
それではようやく, Raspbianのインストールです.
SDカードを「安全に」取り外して, RasberryPi3にSDカードを挿入します. そして電源を入れると終わりです!
ここで, hdmiを持っている人はテレビとRasberryPiをつなげると, インストールされてる画面が出ます. ワクワクしますよね. 面白い.
しばらく待つと, インストールが完了します. 大体1分~5分くらいです.
これでRaspbianのインストールは終了です.
インストールが完了したらSSHをしてみましょう. 2つの方法があります.
1はちょっと知識がないとめんどくさいので, 2を推奨します. 1はあまり詳しく解説しません.
「LAN内で使われているIPアドレスを調べる6つの方法(Linux/Windows)」で紹介されている, arp-scanというコマンドを使います.
ターミナルで, 次のようにコマンドを打って下さい.
$ brew install arp-scan
$ sudo arp-scan -I en0 -l #en0は無線LANのこと.
Password:
Interface: en0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
xxx.xxx.xxx.xxx xx:xx:xx:xx:xx:xx (Unknown)
192.168.0.x xx:xx:xx:xx:xx:xx Raspberry Pi Foundation
192.168.0.x xx:xx:xx:xx:xx:xx Raspberry Pi Foundation (DUP: 2)
xxx.xxx.xxx.xxx xx:xx:xx:xx:xx:xx Hon Hai Precision Ind. Co.,Ltd.
xxx.xxx.xxx.xxx xx:xx:xx:xx:xx:xx (Unknown)
521 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.9: 256 hosts scanned in 1.862 seconds (137.49 hosts/sec). 5 responded
右側に「Raspberry Pi Foundation」と書かれてあるものの左の数字「192.168.0.x」に注目します. 今回は7行目です.
もし, 「Raspberry Pi Foundation」が見つからない場合は, 準備の段階で失敗しているので, やり直すか他のサイトを参考にして下さい. 4
「ssh pi@<先程注目した数字>」みたいなコマンドを打てば良いです.
今回なら「ssh pi@192.168.0.x」ですね.
途中で(yes/no)問われるので, yesと打ちます.
次にpasswordを要求されますが, 「raspberry」と打って下さい.
$ ssh pi@192.168.0.x
The authenticity of host 'raspberrypi.local (xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxx...
Are you sure you want to continue connecting (yes/no)? yes <- yesと打つ.
Warning: Permanently added 'raspberrypi.local,xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx' (ECDSA) to the list of known hosts.
pi@raspberrypi.local's password: #raspberryと打つ
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: Wed Apr 18 01:24:38 2018
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.
pi@raspberrypi:~ $
「pi@raspberrypi:~ $ 」が出ればsshができてます. つまりRaspberryPiを遠隔操作できます. 確認は以上で終わりです.
sshしたのが確認できたら, exitしましょう.
pi@raspberrypi:~ $ exit
「ssh pi@raspberrypi.local」というコマンドを打ちます.
すると, (yes/no)と言われるのでyesと打ちます.
「pi@raspberrypi.local’s password」は, 「raspberry」と入力して下さい.
$ ssh pi@raspberrypi.local
The authenticity of host 'raspberrypi.local (xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxx...
Are you sure you want to continue connecting (yes/no)? yes <- yesと打つ.
Warning: Permanently added 'raspberrypi.local,xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx' (ECDSA) to the list of known hosts.
pi@raspberrypi.local's password: <raspberryと入力>
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: Wed Apr 18 01:24:38 2018
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.
pi@raspberrypi:~ $
「pi@raspberrypi:~ $ 」が出ればsshができてます. つまりRaspberryPiを遠隔操作できます. 確認は以上で終わりです.
sshしたのが確認できたら, exitしましょう.
pi@raspberrypi:~ $ exit
SSHで毎回パスワードを打つのは少しめんどくさいと思います. しかし, sshでの公開鍵認証設定をすると, 毎回パスワードを打たずに済みます. ということで設定していきましょう.
HomeBrewさえインストールされていたら, 「ssh-copy-id」というコマンドが使えるようになるので, それを使っていきます.
ターミナルで, 次のコマンドを打って下さい.
password はRaspberryPi3のパスワードを打ちます. パスワードを変えていないなら, 「raspberry」です.
$ brew install ssh-copy-id
$ ssh-copy-id pi@raspberrypi.local
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/${UserName}/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
pi@raspberrypi.local's password: パスワードを入力.
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'pi@raspberrypi.local'"
and check to make sure that only the key(s) you wanted were added.
これでおkです. では, sshしてみましょう.
$ ssh pi@raspberrypi.local
Linux raspberrypi 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 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.
Last login: Mon May 21 00:32:37 2018 from 192.168.0.5
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.
pi@raspberrypi:~ $
パスワード無しで入れましたね.
これで, OSのダウンロードからSSH設定まで終了です. お疲れ様でした.
今回はOSのダウンロードからSSH設定までしました. よくここまで頑張りました. 偉いw
後半, 画像撮影やHomeBrewの説明など, とっても省略したので, 疑問が多く残ると思います. わからないことがあれば質問下さい.
次は細かいRasberry piの設定を行います.
32GB以上だと, インストールはややこしいです. やっている人は結構いるみたいなので, 「raspbian 64gb sd」で検索してみて下さい. ↩︎
自分はeraseDiskで書き込み禁止状態になっていて苦労しました. ずっと「error: -69877: couldn’t open device」と出ました. 調べてみるとカードリーダの調子が悪かった. こちらのatottoさんの「ちょっと甘めにさして認識させてから奥までさせばちゃんと書き込みできる」に助けられました.
他の解決方法も色々あるので, 「sd 書き込み禁止 mac」で調べると良いかも. ↩︎
「Macから周囲のWi-Fi電波状況をカンタンに確認する方法:Mac Tips」から帯域を調べる方法が確認できるので, こちらからWifiの帯域を確認することができます. ↩︎
「Raspberry Pi 3を初回起動してからSSH接続まで」が良い感じ. ↩︎