0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

RaspberryPi4 ネットワーク編

Last updated at Posted at 2020-02-09

ネットワーク関係

SSH有効化

$ sudo raspi-config
5 -> P2 SSH -> <yes>
$ mkdir ~/.ssh # フォルダを作っておく

Wifi接続

GUIで初期設定した。
平打PWは怖いので、暗号化したpskを生成して/etc/wpa_supplicant/wpa_supplicant.conf に追記
ルートユーザーで以下のコマンドを実行。

$ wpa_passphrase [SSID] [PASS] >> etc/wpa_supplicant/wpa_supplicant.conf

最終的なwpa_supplicant.confは以下。

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP

network={
        ssid="[SSID]"
        psk="[暗号化したPASS]"
        key_mgmt=WPA-PSK
}

固定IP

/etc/dhcpcd.conf に以下を追記

interface wlan0
static ip_address=192.168.11.xx
static routers=192.168.11.1
static domain_name_servers=8.8.8.8

公開鍵認証でSSH

1. 接続元PC

$ cd ~/.ssh/
$ ssh-keygen -t rsa -b 4096 -C "xxx@gmail.com"
Enter file in which to save the key (/home/user/.ssh/id_rsa): /home/user/.ssh/id_rsa_rp4
Enter passphrase (empty for no passphrase): # パスワードを入れる
Enter same passphrase again: # もう一度入れる
# ゴニョゴニョ表示されて鍵が生成される
$ scp ~/.ssh/id_rsa_rp4.pub pi@192.168.11.xx:/home/pi/.ssh # SCPで公開鍵をRaspberryPiに転送する

2. RaspberryPi

公開鍵の設定

cd ~/.ssh/
cat id_rsa_rp4.pub >> authorized_keys
chmod 600 authorized_keys
chmod 700 ~/.ssh
rm ~/.ssh/id_rsa_rp4.pub

SSHの設定変更
/etc/ssh/sshd_config に以下を追記

Port xxxxx # SSHで使うポート番号
PermitRootLogin no # Rootログインの禁止
AuthorizedkeysFile %h/.ssh/authorized_keys # authに使うファイルの指定
PasswordAuthentication no # パスワード認証の禁止

設定できたらRaspberyPiを再起動する

3. 接続

以下のコマンドでRaspberryPiにログインできたらOK

ssh -i ~/.ssh/id_rsa_rp4 pi@192.168.11.xx -p xxxxx # xxxxxはポート番号
0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?