RPi: sshでアクセス

私のRPiはPCからssh経由のヘッドレスアクセスなので、毎回ログインしてパスワードを入力しているが、面倒なのとセキュリティの向上を図って、暗号鍵でアクセスできるようにした。

参考記事はラズパイマガジン2015年冬号(古い (´・ω・`)

  1. PC側の端末Terminalを開く
  2. アクセスするPC側で鍵を生成する

:~$ ssh-keygen -h

  1. 鍵を生成するファイル名を聞いてくるのでそのままENTERしてデフォルトを使う

    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/myName/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase): アクセスIDのパスワード
    Enter same passphrase again: パスワード確認

  2. 鍵の生成ファイル名と相手に渡す鍵のファイル名が通知される

    Your identification has been saved in /home/myName/.ssh/id_rsa. 秘密鍵
    Your public key has been saved in /home/myName/.ssh/id_rsa.pub. 公開鍵
    The key fingerprint is:
    SHA256: 鍵のハッシュ値

  3. PCからラズパイ側に公開鍵id_rsa.pubをコピーする(sshでcpするので、scp)

    scp ~.ssh/id_rsa.pub pi@192.xx.xx.xx:~

  4. ラズパイ側に入りid_rsa.pubが来ていることを確認
  5. 承認鍵ディレクトリに公開鍵の内容を書き込む

    cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys

  6. ラズパイ側の鍵設定を有効にする

    sudo nano /etc/ssh/sshd_config
    PubkeyAuthentication yes

  7. 一旦リブートして鍵が有効になったか確かめる
  8. パスワード認証を無効にする

    PasswordAuthentication no


RPi: Firmwareを更新

ラズパイのOS Raspbianの更新が旨く行ったので、Firmwareの更新もかけることにした。
どうやら、OS自体が古いとFirmwareの更新も旨く行かないようなので、Jessieのときにできなかったことが、Stretchになって簡単にできたのは、幸い。

方法は至極簡単で、ラズパイのOSを最新状態に更新して以下のコマンドを打つだけ。

pi@raspberrypi:~ $ sudo rpi-update

すると、以下のような画面が出てきて必要なFirmwareのアップデートファイルをダウンロードして勝手にやってくれる。

*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
*** Performing self-update
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13403 100 13403 0 0 2696 0 0:00:04 0:00:04 --:--:-- 3147
*** Relaunching after update
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
*** We're running for the first time
*** Backing up files (this will take a few minutes)
*** Remove old firmware backup
*** Backing up firmware
*** Remove old modules backup
*** Backing up modules 4.9.59-v7+

#

This update bumps to rpi-4.9.y linux tree
Be aware there could be compatibility issues with some drivers
Discussion here:
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=167934

#

*** Downloading specific firmware revision (this will take a few minutes)
(中略)
*** If no errors appeared, your firmware was successfully updated to xxx何かのハッシュ値xxxxx
*** A reboot is needed to activate the new firmware

リブートして旨く起動すればおしまい。